思路:
1.用数组把链表中的值保存起来
2.用双指针遍历,比较
/**
* Definition for singly-linked list.
* function ListNode(val, next) {
* this.val = (val===undefined ? 0 : val)
* this.next = (next===undefined ? null : next)
* }
*/
/**
* @param {ListNode} head
* @return {boolean}
*/
var isPalindrome = function(head) {
let res = [];
while(head){
res.push(head.val)
head = head.next
}
let i = 0;
let j = res.length - 1;
while(i<j){
if(res[i]!==res[j]){return false}
i++;
j--;
}
return true
}