题解 | #判断一个链表是否为回文结构#
判断一个链表是否为回文结构
http://www.nowcoder.com/practice/3fed228444e740c8be66232ce8b87c2f
class Solution: def isPail(self , head ): # write code here slow, fast = head, head rev = ListNode(None) while fast and fast.next: fast = fast.next.next slow_next = slow.next slow.next = rev rev = slow slow = slow_next if fast: slow = slow.next while slow: if slow.val != rev.val: return False slow = slow.next rev = rev.next return True