My accepted code in Python~


  • 1
    C
    class Solution:
    # @param s, a string
    # @return a boolean
    def isPalindrome(self, s):
        ret = False
        s = s.lower()
        ss = ""
        for i in s:
            if i.isalnum():
                ss += i
        h = 0
        e = len(ss)-1
        while(h<e):
            if(ss[h] == ss[e]):
                h += 1
                e -= 1
            else:
                break
        if h>=e:
            ret = True
        return ret

Log in to reply
 

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