luoheng
12/27/2019 - 2:48 AM

isPalindrome


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
}