Skip to content

Commit a19cf61

Browse files
committed
valid-palindrome: string concat version
1 parent 921f9b9 commit a19cf61

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

valid-palindrome/invidam.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
func isPalindrome(s string) bool {
2-
var sb strings.Builder
3-
sb.Grow(len(s))
2+
filtered := ""
43
for _, ch := range s {
54
if unicode.IsLetter(ch) || unicode.IsNumber(ch) {
6-
sb.WriteRune(unicode.ToLower(ch))
5+
filtered += string(unicode.ToLower(ch))
76
}
87
}
9-
filtered := sb.String()
10-
for ldx, rdx := 0, len(filtered)-1; ldx < rdx; ldx, rdx = ldx+1, rdx-1 {
8+
9+
for ldx, rdx := 0, len(filtered) - 1; ldx < rdx; ldx, rdx = ldx + 1, rdx - 1 {
1110
if filtered[ldx] != filtered[rdx] {
1211
return false
1312
}

0 commit comments

Comments
 (0)