1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| func isPalindrome(s string) bool { temp := strings.ToLower(s)
i, j := 0, len(temp) - 1
for i < j { for i < j && !isAllowed(temp[i]) { i++ } for i < j && !isAllowed(temp[j]) { j-- }
if temp[i] != temp[j] { return false } else { i++ j-- } }
return true }
func isAllowed(ch byte) bool { return (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') }
|