File tree Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -4,21 +4,22 @@ package main
4
4
import "unicode"
5
5
6
6
func isPalindrome (s string ) bool {
7
- sRunes := []rune (s )
8
- for i , j := 0 , len (s )- 1 ; i < j ; {
9
- if ! (unicode .IsDigit (sRunes [i ]) || unicode .IsLetter (sRunes [i ])) {
10
- i ++
7
+ runeS := []rune (s )
8
+ left , right := 0 , len (s )- 1
9
+ for left < right {
10
+ if ! (unicode .IsDigit (runeS [left ]) || unicode .IsLetter (runeS [left ])) {
11
+ left ++
11
12
continue
12
13
}
13
- if ! (unicode .IsDigit (sRunes [ j ]) || unicode .IsLetter (sRunes [ j ])) {
14
- j --
14
+ if ! (unicode .IsDigit (runeS [ right ]) || unicode .IsLetter (runeS [ right ])) {
15
+ right --
15
16
continue
16
17
}
17
- if unicode .ToLower (sRunes [ i ]) != unicode .ToLower (sRunes [ j ]) {
18
+ if unicode .ToLower (runeS [ left ]) != unicode .ToLower (runeS [ right ]) {
18
19
return false
19
20
}
20
- i ++
21
- j --
21
+ left ++
22
+ right --
22
23
}
23
24
return true
24
25
}
You can’t perform that action at this time.
0 commit comments