剑指 Offer 24. 反转链表(leetcode)

一、思路链接

https://www.bilibili.com/video/BV1Af4y1m7Ct

二、具体题目

https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof/

三、具体代码

var reverseList = function(head) {
    // 需要定义三个指针
    let prev = null;
    let cur = head;
    let next = head;
    while(cur !== null) {
        next = cur.next;
        cur.next = prev;
        prev = cur;
        cur = next;
    }
    return prev;
};
上一篇:JS数组reduce()方法详解及高级技巧


下一篇:编写一个函数,检查输入的链表是否是回文的。