| 6 | ) |
| 7 | |
| 8 | func isPalindrome(s string) bool { |
| 9 | front := 0 |
| 10 | back := len(s) - 1 |
| 11 | s = strings.ToLower(s) |
| 12 | |
| 13 | for front <= back { |
| 14 | for front < len(s) && !isAlphaNumeric(string(s[front])) { |
| 15 | front++ |
| 16 | } |
| 17 | |
| 18 | for back > -1 && !isAlphaNumeric(string(s[back])) { |
| 19 | back-- |
| 20 | } |
| 21 | |
| 22 | // "a:a" case needs initial condition here |
| 23 | if front <= back && s[front] != s[back] { |
| 24 | return false |
| 25 | } |
| 26 | |
| 27 | front++ |
| 28 | back-- |
| 29 | } |
| 30 | |
| 31 | return true |
| 32 | } |
| 33 | |
| 34 | func isAlphaNumeric(s string) bool { |
| 35 | matched, _ := regexp.MatchString("[a-z0-9]", s) |