Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 8aacea0

Browse files
committed
917 finish
1 parent 632cce7 commit 8aacea0

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
package problem0917
22

33
func reverseOnlyLetters(S string) string {
4+
bs := []byte(S)
45

5-
return ""
6+
left, right := 0, len(bs)-1
7+
for left < right {
8+
for left < right && !isLetter(bs[left]) {
9+
left++
10+
}
11+
for left < right && !isLetter(bs[right]) {
12+
right--
13+
}
14+
bs[left], bs[right] = bs[right], bs[left]
15+
left++
16+
right--
17+
}
18+
19+
return string(bs)
20+
}
21+
22+
func isLetter(b byte) bool {
23+
return 'a' <= b && b <= 'z' ||
24+
'A' <= b && b <= 'Z'
625
}

0 commit comments

Comments
 (0)