let reverseLinkedList = function(root) { let reverse = new ListNode(0); let node = root; while (node) { let toAdd = node; let next = node.next; let reversedNext = reverse.next; toAdd.next = reversedNext; reverse.next = toAdd; // node = next; } return reverse.next; }
Categories