题解 | #反转链表#

反转链表

http://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca

/*function ListNode(x){
    this.val = x;
    this.next = null;
}*/
function ReverseList(pHead)
{
    // write code here
    if(pHead == null || pHead.next == null){
        return pHead
    }
    //p1改变后的 头指针 p2尾指针 从左到右改变指针方向
    let p1=null,p2=null
    while(pHead != null){
        p1 = pHead.next 
        pHead.next = p2
        //后移
        p2 = pHead
        pHead = p1
    }
    return p2
}
module.exports = {
    ReverseList : ReverseList
};
全部评论

相关推荐

03-05 12:52
吉林大学 Java
挣K存W养DOG:他的价值在于把他家里积攒的财富回馈给社会
点赞 评论 收藏
分享
会不会进去就面临裁员啊....
MellowWW:我朋友签的美区销售岗,这才是天崩开局
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务