Python concise solution 135 ms runtime


  • 0
    L
    class Solution(object):
        def isPalindrome(self, head):
            """
            :type head: ListNode
            :rtype: bool
            """
            list = [] 
            if head is None or head.next is None:
                return True 
            
            while head is not None:
                list.append(head.val)
                head = head.next
            
            return list == list[::-1]
    

Log in to reply
 

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