LC 234. Palindrome Linked List
1/**
2 * Definition for singly-linked list.
3 * function ListNode(val, next) {
4 * this.val = (val===undefined ? 0 : val)
5 * this.next = (next===undefined ? null : next)
6 * }
7 */
8/**
9 * @param {ListNode} head
10 * @return {boolean}
11 */
12var isPalindrome = function (head) {
13 const vals = []
14 while (head !== null) {
15 vals.push(head.val)
16 head = head.next
17 }
18 for (let i = 0, j = vals.length - 1; i < j; ++i, --j) {
19 if (vals[i] !== vals[j]) return false
20 }
21 return true
22};