查看: 33|回复: 0

用js刷剑指offer(反转链表)

[复制链接]

0

主题

0

回帖

0

积分

积极分子

金币
0
阅读权限
220
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2010-3-26
发表于 2019-9-26 13:51:00 | 显示全部楼层 |阅读模式

题目描述

输入一个链表,反转链表后,输出新链表的表头。

牛客网链接

js代码

/*function ListNode(x){
    this.val = x;
    this.next = null;
}*/
function ReverseList(pHead)
{
    // write code here
    if (!pHead) return null 
    let p = pHead
    let q = pHead.next
    let head = pHead
    head.next = null
    while (q) {
        p = q
        q = q.next
        p.next = head
        head = p
    }
    return head
}


来源:https://www.cnblogs.com/dpnlp/p/yongjs-shua-jian-zhioffer-fan-zhuan-lian-biao.html
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部