Reverse Linked List
cheatsheet1999 opened this issue · 0 comments
cheatsheet1999 commented
Given the head of a singly linked list, reverse the list, and return the reversed list.
With the help with ES6, I found this problem can be easy to solve
var reverseList = function(head) {
let [prev, current] = [null, head];
while(current) {
[prev, current.next, current] = [current, prev, current.next]
}
return prev;
};