Golang Solution


  • 0
    K
    func isPalindrome(s string) bool {
        left := 0
        right := len(s) - 1 
    
        // Asume empty string is a palindrome
        if right < 1 { 
            return true
        }
    
        for left < right {
            // skip no alphanumeric characters
            for (!unicode.IsLetter(rune(s[left])) && !unicode.IsNumber(rune(s[left]))) && left < right {
                fmt.Println("Left: ", left, right, string(s[left]), string(s[right]))
                left++
            }   
            for (!unicode.IsLetter(rune(s[right])) && !unicode.IsNumber(rune(s[right]))) && left < right {
                fmt.Println("Right: ", left, right, string(s[left]), string(s[right]))
                right--
            }   
    
            if strings.ToLower(string(s[left])) != strings.ToLower(string(s[right])) {
                return false
            }   
    
            left++
            right--
        }   
    
        return true
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.