营销型网站与普通网站的比较,网站建设柚子网络科技官网,征婚网站 女 做茶叶生意,域名在哪里续费92. 反转链表 II - 力扣#xff08;LeetCode#xff09; 给你单链表的头指针 head 和两个整数 left 和 right #xff0c;其中 left right 。请你反转从位置 left 到位置 right 的链表节点#xff0c;返回 反转后的链表 206. 反转链表 - 力扣#xff08;LeetCodeLeetCode 给你单链表的头指针 head 和两个整数 left 和 right 其中 left right 。请你反转从位置 left 到位置 right 的链表节点返回 反转后的链表 206. 反转链表 - 力扣LeetCode
next cur-nextcur-next prepre curcur next
反转结束后从原来的链表上看
pre 指向反转这一段的末尾cur 指向反转这一段后续的下一个节点
class Solution {
public:ListNode* reverseList(ListNode* head) {ListNode* pre NULL;ListNode* cur head;while(cur) {ListNode* nextcur-next;cur-next pre;precur;curnext;}return pre;}
}; class Solution {
public:ListNode* reverseBetween(ListNode* head, int left, int right) {ListNode* dummy new ListNode;dummy-next head;ListNode* p0 dummy;for(int i1;ileft-1;i) {p0p0-next;}ListNode* preNULL;ListNode* curp0-next;for(int i1;i(right-left1);i) {ListNode* nextcur-next;cur-nextpre;precur;curnext;}p0-next-nextcur;p0-nextpre;return dummy-next;}
};
往期文章
leetCode 206.反转链表 图解-CSDN博客https://blog.csdn.net/weixin_41987016/article/details/134317963?spm1001.2014.3001.5501