125. 验证回文串

双指针

时间复杂度: O(N)
空间复杂度:O(N)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
func isPalindrome(s string) bool {
temp := strings.ToLower(s)

i, j := 0, len(temp) - 1

for i < j {
for i < j && !isAllowed(temp[i]) {
i++
}
for i < j && !isAllowed(temp[j]) {
j--
}

if temp[i] != temp[j] {
return false
} else {
i++
j--
}
}

return true
}

func isAllowed(ch byte) bool {
return (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')
}

125. 验证回文串
https://blog.jerrylee.me/2021/09/98d75be59f0a.html
作者
Jerry Lee
发布于
2021年9月20日
许可协议