Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8bb1594

Browse files
committed
feat: add go solution to problem No.1576
1 parent f6be116 commit 8bb1594

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,22 @@ public String modifyString(String s) {
108108
}
109109
```
110110

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+
}
114127
```
115128

116129
<!-- tabs:end -->

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,22 @@ public String modifyString(String s) {
103103
}
104104
```
105105

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+
}
109122
```
110123

111124
<!-- tabs:end -->

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /