Need help, why my python code didn't work?


  • 0
    class Solution(object):
    def isPalindrome(self, head):
        """
        :type head: ListNode
        :rtype: bool
        """
        if not head or not head.next: return True
        p=head
        reverse=self.reverseListNode(p)
        while head!=None:
            if head.val!=reverse.val:
                return False
            reverse=reverse.next
            head=head.next
        return True
        
    def reverseListNode(self,head):
        cur=head
        reverse=None
        while cur:
          temp=cur.next
          cur.next=reverse
          reverse=cur
          cur=temp
        return reverse

Log in to reply
 

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