1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| class Solution { public boolean isPalindrome(ListNode head) { LinkedList<ListNode> queue = new LinkedList<ListNode>(); ListNode tmp = head; while (tmp != null) { queue.offer(tmp); tmp = tmp.next; }
while (!queue.isEmpty()){ ListNode frist = queue.pollFirst(); ListNode last = queue.pollLast(); if (last == null) { return true; } if (frist.val != last.val){ return false; } } return true; } }
|