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)9
* @param {ListNode} head12
var isPalindrome = function (head) {15
// Moving slow one step at a time while fast, two steps16
while (fast && fast.next) {18
fast = fast.next.next;20
// This way, slow will end up right after the middle node21
// Reverse the list from that node24
// Now check for equality first half and second half of the list26
if (slow.val !== fast.val) {35
// Function to reverse a LinkedList36
function reverse(head) {39
let nextNode = head.next;