Skip to content

Commit 1aeda69

Browse files
committed
refactor Valid Palindrome
1 parent e1466f5 commit 1aeda69

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

go/valid_palindrome.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@ package main
44
import "unicode"
55

66
func isPalindrome(s string) bool {
7-
r := []rune(s)
8-
for i, j := 0, len(r)-1; i < j; {
9-
if !(unicode.IsLetter(r[i]) || unicode.IsDigit(r[i])) {
7+
sRunes := []rune(s)
8+
for i, j := 0, len(s)-1; i < j; {
9+
if !(unicode.IsDigit(sRunes[i]) || unicode.IsLetter(sRunes[i])) {
1010
i++
1111
continue
1212
}
13-
if !(unicode.IsLetter(r[j]) || unicode.IsDigit(r[j])) {
13+
if !(unicode.IsDigit(sRunes[j]) || unicode.IsLetter(sRunes[j])) {
1414
j--
1515
continue
1616
}
17-
18-
if unicode.ToLower(r[i]) != unicode.ToLower(r[j]) {
17+
if unicode.ToLower(sRunes[i]) != unicode.ToLower(sRunes[j]) {
1918
return false
2019
}
21-
2220
i++
2321
j--
2422
}

0 commit comments

Comments
 (0)