/** * Definition for singly-linked list. * function ListNode(val) { * this.val = val; * this.next = null; * } */ /** * @param {ListNode}head * @return {ListNode} */ var reverseList = function(head) { if (!head) { return head } let parentNode = null while (head) { let current = new ListNode(head.val) current.next = parentNode if (head.next) { let next = new ListNode(head.next.val) next.next = current } else { let next = null return current } parentNode = current head = head.next } return head };