Skip to content

Commit e2755dc

Browse files
authored
Merge pull request gzc426#113 from HanqingZheng/master
验证回文串
2 parents e8531ec + a971917 commit e2755dc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

2018.11.27-leetcode125/家.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
```
2+
func isPalindrome(s string) bool {
3+
if len(s) <= 1 {return true}
4+
low, hi := 0, len(s) - 1
5+
for low < hi {
6+
for ; low < hi && !isValid(s[low]); low++ {}
7+
for ; low < hi && !isValid(s[hi]); hi--{}
8+
x, y := s[low], s[hi]
9+
if (x >= 'A' && x <= 'Z') {x = x - 'A' + 'a'}
10+
if (y >= 'A' && y <= 'Z') {y = y - 'A' + 'a'}
11+
if x != y {return false}
12+
low, hi = low+1, hi-1
13+
}
14+
return true
15+
}
16+
17+
func isValid(b byte) bool {
18+
return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || (b >= '0' && b <= '9')
19+
}
20+
```

0 commit comments

Comments
 (0)