/*function ListNode(x){
this.val = x;
this.next = null;
}*/
function ReverseList(pHead)
{
if(pHead == null || pHead.next == null){
return pHead;
}
//采用头插法。
let head = null;
while(pHead){
let p = pHead.next; //保存pHead的下一个节点
pHead.next = head; //将pHead插到表头
head = pHead; //表头指向pHead
pHead = p; //继续指向下一个需要插入的节点
}
return head;
}
module.exports = {
ReverseList : ReverseList
};