【Lintcode】036.Reverse Linked List II
题目:
Reverse a linked list from position m to n.
Given m, n satisfy the following condition: 1 ≤ m ≤ n ≤ length of list.
Example
Given 1->2->3->4->5->NULL
, m = 2
and n = 4
, return 1->4->3->2->5->NULL
.
题解:
Solution 1 ()
class Solution {
public:
ListNode* reverseBetween(ListNode* head, int m, int n) {
ListNode* first = new ListNode(-);
first->next = head;
ListNode* prev = first; for (int i = ; i < m - ; ++i) {
prev = prev->next;
}
ListNode* cur = prev->next;
for (int i = ; i < n - m; ++i) {
ListNode* tmp = cur->next;
cur->next = tmp->next;
tmp->next = prev->next;
prev->next = tmp;
} return first->next;
}
};
【Lintcode】036.Reverse Linked List II的更多相关文章
- 【原创】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-p ...
- 【LeetCode】92. Reverse Linked List II 解题报告(Python&C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 迭代 递归 日期 题目地址:https://leet ...
- 【leetcode】92. 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-> ...
- 【Lintcode】 035.Reverse Linked List
题目: Reverse a linked list. Example For linked list 1->2->3, the reversed linked list is 3-> ...
- 【Leetcode】92. Reverse Linked List II && 206. Reverse Linked List
The task is reversing a list in range m to n(92) or a whole list(206). All in one : U need three poi ...
- 【LeetCode】206. Reverse Linked List (2 solutions)
Reverse Linked List Reverse a singly linked list. click to show more hints. Hint: A linked list can ...
- 【一天一道LeetCode】#92. Reverse Linked List II
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Reverse ...
- 【LeetCode】206. Reverse Linked List
题目: Reverse a singly linked list. 提示: 此题不难,可以用迭代或者递归两种方法求解.记得要把原来的链表头的next置为NULL: 代码: 迭代: /** * Defi ...
- 【LeetCode】206. Reverse Linked List 解题报告(Python&C++&java)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 迭代 递归 日期 [LeetCode] 题目地址:h ...
随机推荐
- Highcharts使用表格数据绘制图表
Highcharts使用表格数据绘制图表 在Highcharts中,同意用户使用网页中现有的表格数据作为数据来源,然后依据该数据来源绘制图表.对于一个典型的HTML表格.当中,第一列的数据会作为x轴刻 ...
- VESA-ADV7123-SOCKIT-DE2115
/*--VGA Timing--Horizontal :-- ______________ _____________-- | | |--_______________| VIDEO |_______ ...
- android 自定图库(转)
githup: https://github.com/pengjianbo/GalleryFinal GalleryFinal简介 Android自定义相册,实现了拍照.图片选择(单选/多选). 裁剪 ...
- tao.opengl+C#绘制三维模型
一.tao.Opengl技术简介 Opengl是一种C风格的图形库,即opengl中没有类和对象,只有大量的函数.Opengl在内部就是一个状态机,利用不同的函数来修改opengl状态机的状态,以达到 ...
- struts2 jsp提交日期类型转换及国际化实现
概述:下面通过jsp提交输入注册信息信息,同时完成过程文件国家化问题演示说明.[注册日期转换用注解方式实现] 工程截图: 注册页面jsp文件: <%@ page language="j ...
- VS2012,VS2013启用SQLite的Data Provider界面显示
VS2012,VS2013启用SQLite的Data Provider界面显示 VS 2012默认是不带的SQLite的Data Provider,所以无法直接在VS 2012里管理SQLite的数据 ...
- SPOJ LCS2 - Longest Common Substring II 后缀自动机 多个串的LCS
LCS2 - Longest Common Substring II no tags A string is finite sequence of characters over a non-emp ...
- transition_matrix Markov chain
- linux c编程:进程间通信
进程间的通信包括管道,共享内存,信号量通信,消息队列,套借口(socket)和全双工管道通信 首先来看下管道的用法:管道顾名思义,就如同下水道管道一样,当从管道一端流水到另一端的时候,水流的方向是单方 ...
- 阿里云ecs docker使用(2)
1. 退出docker容器 命令 exit 2.sudo docker ps -l 3. sudo docker images 4. sudo docker commit ba300f05c1a3 c ...