一、题目地址
二、具体代码
function ListNode(x){
this.val = x;
this.next = null;
}
// 反转链表需要三个指针的帮助
function ReverseList(pHead)
{
let pre = null;
let cur = pHead;
while(cur) {
let tempCur = new ListNode(cur.val);
if(pre) {
tempCur.next = pre;
}
pre = tempCur;
cur = cur.next;
}
return pre;
}
module.exports = {
ReverseList : ReverseList
};