Python O(1) Space O(n^2) Time Solution


  • 0
    M
    class Solution(object):
        def isPalindrome(self, head):
            """
            :type head: ListNode
            :rtype: bool
            """
            if not head or not head.next:
                return True
            first = head
            while first:
                second = head
                while second.next.next:
                    second = second.next
                if first.val != second.next.val:
                    return False
                second.next = second.next.next
                first = first.next
            return True
    

Log in to reply
 

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