Created
July 13, 2015 03:25
-
-
Save zhyu/662d0a0aa88c5e21c31e to your computer and use it in GitHub Desktop.
Palindrome Linked List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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