Python 10 line O(1) space and O(n) time solution

  • 0
    class Solution(object):
        def isPalindrome(self, head):
            node, result = isPalindromHelper(head, head)
            return result 
    def isPalindromHelper(forward, backward):
        if not forward or not backward:
            return (None,True)
        if backward and not
            return (, forward.val == backward.val)
        node, bool_val = isPalindromHelper(forward,
        return (, node.val == backward.val and bool_val)

Log in to reply

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