LintCode:回文链表

LintCode:回文链表

# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None

class Solution:
    # @param head, a ListNode
    # @return a boolean
    def isPalindrome(self, head):
        if head == None:
            return True
        L = []
        p1 = head
        while p1 != None:
            L.append(p1.val)
            p1 = p1.next
        if L == L[::-1]:
            return True
        return False

你可能感兴趣的:(链表)