class Solution(object):
    def isPalindrome(self, head):
        """
        :type head: ListNode
        :rtype: bool
        """
        list1 = []
        list2 = []
        if head == None:
            return True
        while head:
            list1.append(head.val)
            list2.append(head.val)
            head = head.next
        list1.reverse()
        if list1 == list2:
            return True
        else:
            return False
Copy the code