Created
December 27, 2019 02:48
-
-
Save luoheng23/0dc10edf52834495101ef6e22c87439a 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
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