Skip to content

Commit 2a835ee

Browse files
authored
feat: add golang solutions to lc problem: No.0125 (doocs#884)
1 parent 6b90eb9 commit 2a835ee

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

solution/0100-0199/0125.Valid Palindrome/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,35 @@ impl Solution {
279279
}
280280
```
281281

282+
### **Go**
283+
284+
```go
285+
func isPalindrome(s string) bool {
286+
s = strings.ToLower(s)
287+
left, right := 0, len(s) - 1
288+
for left < right {
289+
for left < right && !verify(s[left]) {
290+
left++
291+
}
292+
for left < right && !verify(s[right]) {
293+
right--
294+
}
295+
if left < right {
296+
if s[left] != s[right] {
297+
return false
298+
}
299+
left++
300+
right--
301+
}
302+
}
303+
return true
304+
}
305+
306+
func verify(ch byte) bool {
307+
return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')
308+
}
309+
```
310+
282311
### **...**
283312

284313
```

solution/0100-0199/0125.Valid Palindrome/README_EN.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,35 @@ impl Solution {
267267
}
268268
```
269269

270+
### **Go**
271+
272+
```go
273+
func isPalindrome(s string) bool {
274+
s = strings.ToLower(s)
275+
left, right := 0, len(s) - 1
276+
for left < right {
277+
for left < right && !verify(s[left]) {
278+
left++
279+
}
280+
for left < right && !verify(s[right]) {
281+
right--
282+
}
283+
if left < right {
284+
if s[left] != s[right] {
285+
return false
286+
}
287+
left++
288+
right--
289+
}
290+
}
291+
return true
292+
}
293+
294+
func verify(ch byte) bool {
295+
return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')
296+
}
297+
```
298+
270299
### **...**
271300

272301
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
func isPalindrome(s string) bool {
2+
s = strings.ToLower(s)
3+
left, right := 0, len(s) - 1
4+
for left < right {
5+
for left < right && !verify(s[left]) {
6+
left++
7+
}
8+
for left < right && !verify(s[right]) {
9+
right--
10+
}
11+
if left < right {
12+
if s[left] != s[right] {
13+
return false
14+
}
15+
left++
16+
right--
17+
}
18+
}
19+
return true
20+
}
21+
22+
func verify(ch byte) bool {
23+
return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')
24+
}

0 commit comments

Comments
 (0)