1576. Replace All 's to Avoid Consecutive Repeating Characters

Updated: 2024-03-12
1 min read
[]

On This Page

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)