一:题目
二:上码
/*** Definition for singly-linked list.* public class ListNode {* int val;* ListNode next;* ListNode() {}* ListNode(int val) { this.val = val; }* ListNode(int val, ListNode next) { this.val = val; this.next = next; }* }*/
class Solution {public List<Integer> getList(ListNode head) {List<Integer> list = new ArrayList<>();while (head != null) {list.add(head.val);head = head.next;}return list;}public boolean isPalindrome(ListNode head) {List<Integer> list = getList(head);for (int i = 0, j = list.size() -1; i < list.size()/2; i++,j--) {if (list.get(i) != list.get(j)) return false;}return true;}
}