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 //纯粹模拟反转字符是否等于字符 Stack<Integer> Stack=new Stack<Integer>(); ListNode node=head; int len=0; while(node!=null){ len++; Stack.push(node.val); node=node.next; } node=head; while(len-->0){ if(node.val!=Stack.pop())return false; node=node.next; } return true; } }