/** * 链表转为list, 采用双指针,操作链表双指针个,由于没有pre指针不好操作,转为list * * @param head * @return */ public boolean isPail(ListNode head) { // write code here List<Integer> res = new ArrayList<>(); while (head != null) { res.add(head.val); head = head.next; } for (int x = 0, y = res.size() - 1; x < y; x++, y--) { if (!res.get(x).equals(res.get(y))) { return false; } } return true; }