import java.util.*;
/*
* 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> nums = new LinkedList<>();
ListNode p = head;
while(p != null) {
nums.addLast(p.val);
p = p.next;
}
while(nums.size() > 1 && (int)nums.getFirst() == (int)nums.getLast()) {
nums.removeFirst();
nums.removeLast();
}
System.out.println(nums.size());
return nums.size() <= 1;
}
}