We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 675bc31 + f78d666 commit 1df7356Copy full SHA for 1df7356
go/125-Valid-Palindrome.go
@@ -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
18
19
20
+ if left != right {
21
+ return false
22
23
24
25
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