import java.util.*;
import java.util.Collections.*;
/*
* public class ListNode {
* int val;
* ListNode next = null;
* }
*/
public class Solution {
/**
*
* @param head ListNode类 the head
* @return bool布尔型
*/
public boolean isPail (ListNode head) {
// write code here
if(head==null||head.next==null){
return true;
}
LinkedList<Integer> linkedlist = new LinkedList<>();
ListNode node1 = head;
while(node1!=null){
linkedlist.push(node1.val);
node1=node1.next;
}
ListNode node2 = head;
while(node2!=null){
if(node2.val!=linkedlist.pop()){
return false;
}
node2=node2.next;
}
return true;
}
}