Skip to content

Commit 921f9b9

Browse files
committed
valid-palindrome: string builder version
1 parent f3f5d84 commit 921f9b9

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

valid-palindrome/invidam.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
func isPalindrome(s string) bool {
2+
var sb strings.Builder
3+
sb.Grow(len(s))
4+
for _, ch := range s {
5+
if unicode.IsLetter(ch) || unicode.IsNumber(ch) {
6+
sb.WriteRune(unicode.ToLower(ch))
7+
}
8+
}
9+
filtered := sb.String()
10+
for ldx, rdx := 0, len(filtered)-1; ldx < rdx; ldx, rdx = ldx+1, rdx-1 {
11+
if filtered[ldx] != filtered[rdx] {
12+
return false
13+
}
14+
}
15+
return true
16+
}

0 commit comments

Comments
 (0)