Simple Python Solution


  • 0
    P
    def isPalindrome(self, head):
        
        if not head or not head.next : return True
    
        slow = head
        fast = head.next
        ans = [slow.val]
        
        while fast.next and fast.next.next :
            fast = fast.next.next
            slow = slow.next
            ans.append(slow.val)
        
        if not fast.next :
            two = slow.next
        else : 
            two = slow.next.next
        while ans :
            temp = ans.pop()
            if temp != two.val :
                return False
            else :
                two = two.next
        return True

Log in to reply
 

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