// 首先的思路是用栈,后来想到是否可以用双向链表,给他添加一个方向再删除原来的
function ListNode(x){
this.val = x;
this.next = null;
}
function ReverseList(pHead)
{
// write code here
// 空链表或只有一个节点的链表
if (pHead == null || pHead.next == null) {
return pHead;
}
while (pHead.next != null) {
pHead.next.forward = pHead;
pHead = pHead.next;
}
var point = new ListNode(0);
// point.next.forward = null;
point.next = pHead;
while (point.next.forward != null) {
point.next.next = point.next.forward;
point = point.next;
point.next.next = null;
}
return pHead
}
module.exports = {
ReverseList : ReverseList
};