Skip to content

Commit cb07e4a

Browse files
aQuaaQua
aQua
authored and
aQua
committed
125 accepted. 6ms > 3ms.
1 parent 96b6562 commit cb07e4a

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
11
package Problem0125
22

3+
import (
4+
"strings"
5+
)
6+
37
func isPalindrome(s string) bool {
8+
s = strings.ToLower(s)
9+
i, j := 0, len(s)-1
10+
for i < j {
11+
for i < j && !isChar(s[i]) {
12+
i++
13+
}
14+
for i < j && !isChar(s[j]) {
15+
j--
16+
}
17+
if s[i] != s[j] {
18+
return false
19+
}
20+
i++
21+
j--
22+
}
423

524
return true
625
}
26+
27+
func isChar(c byte) bool {
28+
if ('a' <= c && c <= 'z') || ('0' <= c && c <= '9') {
29+
return true
30+
}
31+
return false
32+
}

Algorithms/0125.valid-palindrome/valid-palindrome_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ func Test_Problem0125(t *testing.T) {
1616
ans bool
1717
}{
1818

19+
{
20+
"0p",
21+
false,
22+
},
23+
24+
{
25+
"0",
26+
true,
27+
},
28+
1929
{
2030
"race a car",
2131
false,

0 commit comments

Comments
 (0)