public class Solution {
public boolean isPalindrome(ListNode head) {
if(head==null||head.next==null)return true;
ListNode newhead=head;
int len=0;
while(newhead!=null){
newhead=newhead.next;
len++;
}
int i=0;
while(i<len/2){
ListNode temp=head.next;
head.next=newhead;
newhead=head;
head=temp;
i++;
}
if(len%2==1)head=head.next;
while(head!=null){
if(head.val!=newhead.val)return false;
head=head.next;
newhead=newhead.next;
}
return true;
}
}