Validar palabra palíndroma en Go
func isPalindrome(s string) bool {
clean := toAlpha(s)
left := 0
right := len(clean) - 1
for left <= right {
if clean[left] != clean[right] {
return false;
}
left++
right--
}
return true
}
func toAlpha(s string) string {
r := regexp.MustCompile("[^a-zA-Z0-9]")
return strings.ToLower(r.ReplaceAllString(s, ""))
}
© Emilio Font.RSS