Leetcode 92206:反转链表-反转链表 II
Posted hello,是翠花呀
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode 92206:反转链表-反转链表 II相关的知识,希望对你有一定的参考价值。
反转链表 II
var reverseBetween = function (head, left, right)
let cur = head;
let pre = null;
let i = 1;
if (left === right)
return head;
while (i < left)
pre = cur;
cur = cur.next;
i++;
let newCur = cur;
let newPre = pre;
while (i >= left && i <= right)
let next = cur.next;
cur.next = pre;
pre = cur;
cur = next;
i++;
newCur.next = cur;
if (newPre)
newPre.next = pre;
else
head = pre;
return head;
;
反转链表
var reverseList = function (head)
let cur = head
let pre = null
while(cur !== null)
let next = cur.next
cur.next = pre
pre = cur
cur = next
return pre
以上是关于Leetcode 92206:反转链表-反转链表 II的主要内容,如果未能解决你的问题,请参考以下文章
Leetcode练习(Python):链表类:第92题:反转链表 II:反转从位置 m 到 n 的链表。请使用一趟扫描完成反转。