Skip to content

Commit f6be116

Browse files
committed
feat: add python solution to problem No.1576
1 parent c530212 commit f6be116

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

solution/1500-1599/1576.Replace All ?'s to Avoid Consecutive Repeating Characters/README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,18 @@
6767
<!-- 这里可写当前语言的特殊实现逻辑 -->
6868

6969
```python
70-
70+
class Solution:
71+
def modifyString(self, s: str) -> str:
72+
s = list(s)
73+
for i in range(len(s)):
74+
if s[i] == '?':
75+
ahead = ' ' if i == 0 else s[i - 1]
76+
behind = ' ' if i == len(s) - 1 else s[i + 1]
77+
for c in string.ascii_lowercase:
78+
if c != ahead and c != behind:
79+
s[i] = c
80+
break
81+
return "".join(s)
7182
```
7283

7384
### **Java**

solution/1500-1599/1576.Replace All ?'s to Avoid Consecutive Repeating Characters/README_EN.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,18 @@
6363

6464

6565
```python
66-
66+
class Solution:
67+
def modifyString(self, s: str) -> str:
68+
s = list(s)
69+
for i in range(len(s)):
70+
if s[i] == '?':
71+
ahead = ' ' if i == 0 else s[i - 1]
72+
behind = ' ' if i == len(s) - 1 else s[i + 1]
73+
for c in string.ascii_lowercase:
74+
if c != ahead and c != behind:
75+
s[i] = c
76+
break
77+
return "".join(s)
6778
```
6879

6980
### **Java**

0 commit comments

Comments
 (0)