Skip to content

Instantly share code, notes, and snippets.

@zhyu
Created July 13, 2015 03:25
Show Gist options
  • Save zhyu/662d0a0aa88c5e21c31e to your computer and use it in GitHub Desktop.
Save zhyu/662d0a0aa88c5e21c31e to your computer and use it in GitHub Desktop.
Palindrome Linked List
class Solution:
def isPalindrome(self, head):
rhead = None
slow = fast = head
while fast and fast.next:
fast = fast.next.next
slow.next, slow, rhead = rhead, slow.next, slow
if fast:
slow = slow.next
while rhead and rhead.val == slow.val:
rhead = rhead.next
slow = slow.next
return not rhead
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment