1576. Replace All 's to Avoid Consecutive Repeating Characters

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 1576

class Solution:
    def modifyString(self, s: str) -> str:
        s = list(s)
        n = len(s)
        for i in range(n):
            if s[i] == "?":
                for c in "abc":
                    if (i and s[i - 1] == c) or (i + 1 < n and s[i + 1] == c):
                        continue
                    s[i] = c
                    break
        return "".join(s)