# 1576.替换所有的问号

[原题](https://leetcode-cn.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters/)

对于？号，只需要考虑左右是否相同，可以一次遍历，先比左再比右，若相同则取字母表下一位，直到与左右都不同为止

```python
class Solution:
    def modifyString(self, s: str) -> str:
        n = len(s)
        if n == 1:
            return "a" if s == "?" else s
        alphabet = 'abcdefghijklmnopqrstuvwxyz'
        slist = list(s)
    
        for i in range(n):
            if slist[i] == '?':
                for a in alphabet:
                    if i == 0 and a == slist[i+1]:
                        continue
                    elif i > 0 and i < n-1 and (slist[i-1] == a or slist[i+1] == a):
                        continue
                    elif i == n-1 and a == slist[i-1]:
                        continue
                    else:
                        slist[i] = a
                        break
        return ''.join(slist)           
```
