Fast, simple, readable Python 3 solution using itertools 92ms

  • 0
    import itertools as it
    def is_palindrome(string): 
        left = it.islice(string, len(string)//2)
        right = it.islice(reversed(string), len(string)//2)
        for l, r in zip(left, right):
            if l != r:
                return False
        return True
    class Solution:
        def isPalindrome(self, s):
            :type s: str
            :rtype: bool
            string = ''.join(filter(str.isalnum, s.lower()))
            return is_palindrome(string)

Log in to reply

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