❤leetcode,python2❤请判断一个链表是否为回文链表。

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

你可能感兴趣的:(❤leetcode,python2❤请判断一个链表是否为回文链表。)