31 lines
463 B
Go
31 lines
463 B
Go
package valid_palindrome
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
var notAlphanumeric = regexp.MustCompile(`[^a-zA-Z0-9]`)
|
|
|
|
func KeepAlphanumeric(text string) string {
|
|
return notAlphanumeric.ReplaceAllString(text, "")
|
|
}
|
|
|
|
func IsPalindrome(text string) bool {
|
|
scrubbed := strings.ToLower(KeepAlphanumeric(text))
|
|
|
|
start := 0
|
|
end := len(scrubbed) - 1
|
|
|
|
for start < end {
|
|
if scrubbed[start] != scrubbed[end] {
|
|
return false
|
|
}
|
|
|
|
start++
|
|
end--
|
|
}
|
|
|
|
return true
|
|
}
|