Python list comprehension considered good or not?

  • 0

    Is python list comprehension considered good in interview or not ? I think if list comprehension is valid then so should be using String.reverse(), no?

    Nothing notable about my answer though just to avoid creating a new string.

    def isPalindrome(self, s):
        if s == None:
            return False
        i = 0
        j = len(s) - 1
        while i <= j:
            while not s[i].isalnum() and i < j:
                i += 1
            while not s[j].isalnum() and i < j:
                j -= 1
            if i != j and s[i].lower() != s[j].lower():
                return False
            i += 1
            j -= 1
        return True

Log in to reply

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