My accept python code

  • 0
    # Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, x):
    #         self.val = x
    # = None
    class Solution:
        # @param {ListNode} head
        # @return {boolean}
        def isPalindrome(self, head):
            #first judge the 1 or 0 node
            if head is None or is None:
                return True
            # find the mid Node 
            fast, slow = head, head
            while is not None and is not None:
                slow =
                fast =
            #get the mid point 
            midPoint = slow
            endPoint =
            cur = # first node Doing the insert
   = None
            while(cur is not None):
                nextNode =
       = cur
                cur = nextNode
            # judge if the two link list
            left, right = head,
            while (right is not None):
                if left.val == right.val:
                    left =
                    right =
                    return False
            return True

Log in to reply

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