Skip to content

Commit 1df7356

Browse files
authored
Merge pull request neetcode-gh#652 from MaratKhakim/125-Valid-Palindrome
125. Valid Palindrome
2 parents 675bc31 + f78d666 commit 1df7356

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

go/125-Valid-Palindrome.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
func isPalindrome(s string) bool {
2+
i := 0
3+
j := len(s) - 1
4+
arr := []rune(s)
5+
6+
for i < j {
7+
left := unicode.ToLower(arr[i])
8+
right := unicode.ToLower(arr[j])
9+
10+
if !isLetterOrDigit(left) {
11+
i++
12+
continue
13+
}
14+
15+
if !isLetterOrDigit(right) {
16+
j--
17+
continue
18+
}
19+
20+
if left != right {
21+
return false
22+
}
23+
24+
i++
25+
j--
26+
}
27+
28+
return true
29+
}
30+
31+
func isLetterOrDigit(s rune) bool {
32+
return unicode.IsLetter(s) || unicode.IsDigit(s)
33+
}

0 commit comments

Comments
 (0)