Python two-pointer with 69ms


  • 0
    T
        def isPalindrome(self, s):
            """
            :type s: str
            :rtype: bool
            """
            if not s:
              return True
            st = ''.join(i for i in s.lower() if i.isalnum())
            i = 0 
            j = len(st) - 1
            flag = True
            while i <= j:
                if st[i] != st[j]:
                    flag = False
                    break
                else:
                    flag = True
                    i += 1
                    j -= 1
                    
            return flag

Log in to reply
 

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