import java.util.*;

/*

  • public class ListNode {
  • int val;
  • ListNode next = null;
  • } */

public class Solution {

//利用栈FILO的特性,完成回文判断

public boolean isPail (ListNode head) {
    // write code here
    Stack<Integer> tempStack = new Stack<>();
    ListNode tmpNode = head;
    while(tmpNode != null){
        tempStack.push(tmpNode.val);
        tmpNode = tmpNode.next;
    }
    while(head != null){
        if(head.val != tempStack.pop()){
            return false;
        }
        head = head.next;
    }
    return true;
}

}