- 68ms
- 73%
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def isPalindrome(self, head: ListNode) -> bool:
rev = None
slow = fast = head
while fast and fast.next:
fast = fast.next.next
slow, rev, rev.next = slow.next, slow, rev
if fast:
slow = slow.next
while rev and rev.val==slow.val:
rev = rev.next
slow = slow.next
return not rev