File tree 2 files changed +24
-2
lines changed
solution/1500-1599/1576.Replace All ?'s to Avoid Consecutive Repeating Characters
2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 67
67
<!-- 这里可写当前语言的特殊实现逻辑 -->
68
68
69
69
``` 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)
71
82
```
72
83
73
84
### ** Java**
Original file line number Diff line number Diff line change 63
63
64
64
65
65
``` 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)
67
78
```
68
79
69
80
### ** Java**
You can’t perform that action at this time.
0 commit comments