# 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:
if not head :
return True
fast=head
slow=head
while(fast.next and fast.next.next):
fast=fast.next.next
slow=slow.next
slow=slow.next
if not slow:
return True
newhead=ListNode(slow.val)
while(slow.next):
slow=slow.next
cur=ListNode(slow.val)
cur.next=newhead
newhead=cur
while(newhead):
if newhead.val!=head.val:
return False
head=head.next
newhead=newhead.next
return True