import java.util.*;

/*
 * public class ListNode {
 *   int val;
 *   ListNode next = null;
 *   public ListNode(int val) {
 *     this.val = val;
 *   }
 * }
 */

public class Solution {
    public boolean isPail (ListNode head) {
        ArrayList<Integer> arr=new ArrayList<>();
        while(head!=null){
            arr.add(head.val);
            head=head.next;
        }
        int left=0;
        int right=arr.size()-1;
        while(left<=right){
            int n1=arr.get(left);
            int n2=arr.get(right);
            if(n1!=n2){
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
}