题解 | #反转链表#递归解法,JavaScript
反转链表
http://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca
/*function ListNode(x){
this.val = x;
this.next = null;
}*/
function ReverseList(pHead)
{
if(!pHead || !pHead.next) return pHead;
let newhead = ReverseList(pHead.next);
pHead.next.next = pHead;
pHead.next = null;
return newhead;
}
module.exports = {
ReverseList : ReverseList
};
简单的递归