/*function ListNode(x){
this.val = x;
this.next = null;
}*/
// Recursion
function ReverseList(head) {
if (head === null || head.next === null) return head;
let res = ReverseList(head.next);
head.next.next = head;
head.next = null;
return res;
}
// Iteration
function ReverseList(head){
// write code here
if (head === null) return head;
let curr = head;
let pre = null;
let next = null;
while (curr) {
next = curr.next;
curr.next = pre;
pre = curr;
curr = next;
}
head = pre;
return head;
}
module.exports = {
ReverseList : ReverseList
};