leetcode 之Reverse Linked List II(15)

这题用需要非常细心,用头插法移动需要考虑先移动哪个,只需三个指针即可。
ListNode *reverseList(ListNode *head, int m, int n)
{
ListNode dummy(-);
dummy.next = head;
ListNode *prev = &dummy; for (int i = ; i < m - ; i++)
prev = prev->next;//要调整的数之前的那个数 ListNode *head2 = prev;
prev = head2->next;
ListNode *curr = prev->next;
for (int i = m; i < n; i++)
{
prev->next = curr->next;//头插法
curr->next = head2->next;
head2->next = curr; curr = prev->next;
}
}
leetcode 之Reverse Linked List II(15)的更多相关文章
- 【leetcode】Reverse Linked List II
Reverse Linked List II Reverse a linked list from position m to n. Do it in-place and in one-pass. F ...
- leetcode -day30 Reverse Linked List II
1. Reverse Linked List II Reverse a linked list from position m to n. Do it in-place and in one- ...
- [LeetCode] 92. Reverse Linked List II 反向链表II
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...
- Java for LeetCode 092 Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1-> ...
- [LeetCode] 92. Reverse Linked List II 倒置链表之二
Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Exa ...
- 【leetcode】Reverse Linked List II (middle)
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...
- leetcode 92 Reverse Linked List II ----- java
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...
- leetcode:Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...
- LeetCode 92. Reverse Linked List II倒置链表2 C++
Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Exa ...
随机推荐
- [Vue源码分析] v-model实现原理
最近小组有个关于vue源码分析的分享会,提前准备一下… 前言:我们都知道使用v-model可以实现数据的双向绑定,及实现数据的变化驱动dom的更新,dom的更新影响数据的变化.那么v-model是怎么 ...
- BZOJ3653 & 洛谷3899:谈笑风生——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=3653 https://www.luogu.org/problemnew/show/P3899 设 ...
- BZOJ1057:[ZJOI2007]棋盘制作——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1057 https://www.luogu.org/problemnew/show/P1169 国际象 ...
- HDU3065:病毒侵袭持续中——题解
http://acm.hdu.edu.cn/showproblem.php?pid=3065 ———————————————————————————— Problem Description 小t非常 ...
- Codeforces Round #340 (Div. 2)B
B. Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- AtCoder Grand Contest 031 B - Reversi(DP)
B - Reversi 题目链接:https://atcoder.jp/contests/agc031/tasks/agc031_b 题意: 给出n个数,然后现在你可以对一段区间修改成相同的值,前提是 ...
- nginx 服务器启动、终止、重启
启动 在linux系统下输入命令: nginx地址 -c nginx配置文件 就可启动nginx eg:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/ ...
- [LeetCode] 递推思想的美妙 Best Time to Buy and Sell Stock I, II, III O(n) 解法
题记:在求最大最小值的类似题目中,递推思想的奇妙之处,在于递推过程也就是比较求值的过程,从而做到一次遍历得到结果. LeetCode 上面的这三道题最能展现递推思想的美丽之处了. 题1 Best Ti ...
- B树及其变种
B树是为磁盘或其他直接存取的辅助存储设备而设计的一种平衡搜索树.B树类似于红黑树,但它们在降低磁盘I/O操场数方面要更好一些.许多数据库系统使用B树或B树的变种来存储信息. 介绍 常见的动态查找树包括 ...
- UVALive-3263 That Nice Euler Circuit (几何欧拉定理)
https://vjudge.net/problem/UVALive-3263 平面上有一个n个端点的一笔画,第n个端点总是和第一个端点重合,因此图示一条闭合曲线. 组成一笔画的线段可以相交,但不会部 ...