题解 | #判断一个链表是否为回文结构#
判断一个链表是否为回文结构
http://www.nowcoder.com/practice/3fed228444e740c8be66232ce8b87c2f
step1:定义一个数组temp,用于存储链表中的值。 step2:判断数组翻转后的结果和输入的正序结果是否一致。
class ListNode(object):
def __init__(self, x=0, next=None):
self.val=x
self.next=next
class Solution(object):
def isPail(self, head):
temp = list()
while(head):
temp.append(head.val)
head = head.next
if temp==temp[::-1]:
return True
else:
return False