Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
Note: For the purpose of this problem, we define empty string as valid palindrome.
Example 1:
Input: “A man, a plan, a canal: Panama”
Output: true
Example 2:
Input: “race a car”
Output: false
func isPalindrome(s string) bool {
if len(s) <= 1 {
return true
}
l := 0
r := len(s) - 1
for l < r {
for l < r && (!unicode.IsLetter(rune(s[l])) && !unicode.IsNumber(rune(s[l]))) {
l++
}
for r > l && (!unicode.IsLetter(rune(s[r])) && !unicode.IsNumber(rune(s[r]))) {
r--
}
fmt.Println(string(s[l]), string(s[r]), unicode.IsLetter(rune(s[l])))
if unicode.ToLower(rune(s[l])) != unicode.ToLower(rune(s[r])) {
return false
}
l++
r--
}
return true
}