File tree 2 files changed +32
-6
lines changed
solution/1500-1599/1576.Replace All ?'s to Avoid Consecutive Repeating Characters
2 files changed +32
-6
lines changed Original file line number Diff line number Diff line change @@ -108,9 +108,22 @@ public String modifyString(String s) {
108
108
}
109
109
```
110
110
111
- ### ** ...**
112
- ```
113
-
111
+ ### ** Go**
112
+ ``` go
113
+ func modifyString (s string ) string {
114
+ data := []byte (" " + s + " " )
115
+ for i , c := range data {
116
+ if c == byte (' ?' ) {
117
+ ahead , behind := data[i-1 ], data[i+1 ]
118
+ for t := byte (' a' ); t <= byte (' z' ); t++ {
119
+ if t != ahead && t != behind {
120
+ data[i] = t
121
+ }
122
+ }
123
+ }
124
+ }
125
+ return string (data[1 : len (data)-1 ])
126
+ }
114
127
```
115
128
116
129
<!-- tabs:end -->
Original file line number Diff line number Diff line change @@ -103,9 +103,22 @@ public String modifyString(String s) {
103
103
}
104
104
```
105
105
106
- ### ** ...**
107
- ```
108
-
106
+ ### ** Go**
107
+ ``` go
108
+ func modifyString (s string ) string {
109
+ data := []byte (" " + s + " " )
110
+ for i , c := range data {
111
+ if c == byte (' ?' ) {
112
+ ahead , behind := data[i-1 ], data[i+1 ]
113
+ for t := byte (' a' ); t <= byte (' z' ); t++ {
114
+ if t != ahead && t != behind {
115
+ data[i] = t
116
+ }
117
+ }
118
+ }
119
+ }
120
+ return string (data[1 : len (data)-1 ])
121
+ }
109
122
```
110
123
111
124
<!-- tabs:end -->
You can’t perform that action at this time.
0 commit comments