Skip to content

Instantly share code, notes, and snippets.

@mdbooth
Created April 27, 2024 11:09
Show Gist options
  • Save mdbooth/a950352c05da12b24237a7f7a492b3b3 to your computer and use it in GitHub Desktop.
Save mdbooth/a950352c05da12b24237a7f7a492b3b3 to your computer and use it in GitHub Desktop.
package ispalindrome
import (
"unicode"
)
// Attempt 1
/*
func isPalindrome(s string) bool {
for i := range s {
if s[i] != s[len(s)-1-i] {
return false
}
}
return true
}
*/
func isPalindrome(s string) bool {
var runes []rune
for _, r := range s {
if unicode.IsLetter(r) {
runes = append(runes, unicode.ToLower(r))
}
}
for i := range runes {
if runes[i] != runes[len(runes)-1-i] {
return false
}
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment