Created
April 27, 2024 11:09
-
-
Save mdbooth/a950352c05da12b24237a7f7a492b3b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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