Skip to content

Commit b787b74

Browse files
committed
feat: add python and golang solution to problem No.1576
1 parent 7c87fd1 commit b787b74

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
func modifyString(s string) string {
2+
data := []byte(" " + s + " ")
3+
for i, c := range data {
4+
if c == byte('?') {
5+
ahead, behind := data[i-1], data[i+1]
6+
for t := byte('a'); t <= byte('z'); t++ {
7+
if t != ahead && t != behind {
8+
data[i] = t
9+
}
10+
}
11+
}
12+
}
13+
return string(data[1 : len(data)-1])
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def modifyString(self, s: str) -> str:
3+
s = list(s)
4+
for i in range(len(s)):
5+
if s[i] == '?':
6+
ahead = ' ' if i == 0 else s[i - 1]
7+
behind = ' ' if i == len(s) - 1 else s[i + 1]
8+
for c in string.ascii_lowercase:
9+
if c != ahead and c != behind:
10+
s[i] = c
11+
break
12+
return "".join(s)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy