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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_22795513/article/details/80663393
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

猜你喜欢

转载自blog.csdn.net/qq_22795513/article/details/80663393
今日推荐