Skip to content

Commit 64be7d5

Browse files
committed
Create valid-palindrome.go
1 parent 8c4b514 commit 64be7d5

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

valid-palindrome.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package leetcode_solutions_golang
2+
3+
import "strings"
4+
5+
//https://leetcode.com/problems/valid-palindrome/
6+
func isPalindrome3(s string) bool {
7+
s = strings.ToLower(s)
8+
left := 0
9+
right := len(s) - 1
10+
for left < right {
11+
if !((s[left] >= 'a' && s[left] <= 'z') || (s[left] >= '0' && s[left] <= '9')) {
12+
left++
13+
continue
14+
}
15+
if !((s[right] >= 'a' && s[right] <= 'z') || (s[right] >= '0' && s[right] <= '9')) {
16+
right--
17+
continue
18+
}
19+
20+
if s[left] != s[right] {
21+
return false
22+
}
23+
left++
24+
right--
25+
}
26+
return true
27+
}

0 commit comments

Comments
 (0)