原题
回文 水题
function ListNode(val) {
this.val = val;
this.next = null;
}
/**
* @param {ListNode} head
* @return {boolean}
*/
var isPalindrome = function(head) {
var list = [];
while (head) {
list.push(head.val);
head = head.next;
}
for (let i = 0; i < (list.length + 1) / 2; i++) {
if (list[i] !== list[list.length - i - 1]) {
return false;
}
}
return true;
};
网友评论