varisPalindrome=function(head) {if (head ===null) returntrue;if (head.next ===null) returntrue;let one = head;let two = head;while (two.next !==null&&two.next.next !==null) { one =one.next; two =two.next.next; }// 1 2 3 => one is 1 => pivot should be 3// 1 2 3 4 => one is 2 => pivot should be 3// so one.next is pivot for odd and evenconstpivot=one.next; one = head; two =reverse(pivot);while (two !==null) {if (two.val !==one.val) returnfalse; one =one.next; two =two.next; }returntrue;};functionreverse(node) {let prev =null;let curr = node;while (curr !==null) {constnext=curr.next;curr.next = prev; prev = curr; curr = next; }return prev;}