Search for a command to run...
Initialization
prev starts as null and temp at the head. Reversing means pointing each node back at prev instead of forward.
Three Pointers
1function reverseList(head) {2 let temp = head;3 let prev = null;//prev: nulltemp: 14 5 while (temp !== null) {6 // Save the rest of the list before overwriting7 const front = temp.next;8 9 // Flip this link backwards10 temp.next = prev;11 12 // Advance both pointers13 prev = temp;14 temp = front;15 }16 17 // prev is the new head18 return prev;19}