Skip to content

Instantly share code, notes, and snippets.

@luoheng23
Created December 27, 2019 02:48
Show Gist options
  • Save luoheng23/0dc10edf52834495101ef6e22c87439a to your computer and use it in GitHub Desktop.
Save luoheng23/0dc10edf52834495101ef6e22c87439a to your computer and use it in GitHub Desktop.
func isalpha(c byte) bool {
return c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z'
}
func toLower(c byte) byte {
if c >= 'A' && c <= 'Z' {
c += 'a' - 'A'
}
return c
}
func isPalindrome(s string) bool {
for i, j := 0, len(s)-1; i < j; i++ {
if isalpha(s[i]) {
for !isalpha(s[j]) {
j--
}
if toLower(s[i]) != toLower(s[j]) {
return false
}
j--
}
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment