I'm implementing a reversed linked list using Javascript.
var reverseList = function(head) {
if (!head || !head.next) {
return head;
}
let tmp = reverseList(head.next);
//head.next = head;
head.next.next = head;
head.next = undefined;
return tmp;
};
The given code is my previous solution, which didn't work. So, I had to go to .next.next element. Why do I need to do it?
Thanks