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->2->3->4->5->NULL
, m = 2 and n = 4,
return 1->4->3->2->5->NULL
.
Note:
Given m, n satisfy the following condition:
1 ≤ m ≤ n ≤ length of list.
class Solution {
public ListNode reverseBetween(ListNode head, int m, int n) {
if(head == null) return head;
ListNode fakehead = new ListNode(0);
fakehead.next = head;
ListNode pre = fakehead; for (int i = 0; i < m-1;i++) pre = pre.next; ListNode start = pre.next;
ListNode then = start.next; for(int i = 0 ;i < n -m ;i++){
start.next= then.next;
then.next = pre.next;
pre.next = then;
then=start.next;
}
return fakehead.next;
}
}
92. Reverse Linked List II(链表部分反转)的更多相关文章
- 92. Reverse Linked List II【Medium】
92. Reverse Linked List II[Medium] Reverse a linked list from position m to n. Do it in-place and in ...
- [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-> ...
- 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- ...
- [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】92. Reverse Linked List II 解题报告(Python&C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 迭代 递归 日期 题目地址:https://leet ...
- 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 ...
- [leetcode]92. Reverse Linked List II反转链表2
Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Exa ...
- 92. Reverse Linked List II 翻转链表II
Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Exa ...
- [LeetCode]92. Reverse Linked List II反转部分链表
/* 重点还是反转链表 思路就是中间的反转,然后两头接上 */ public ListNode reverseBetween(ListNode head, int m, int n) { if (he ...
随机推荐
- 上传绕过WAF的tips大全
原始默认状态: ——WebKitFormBoundary2smpsxFB3D0KbA7D Content-Disposition: form-data; name=”filepath”; filena ...
- Dubbo(四) -- telnet命令
一.telnet的作用 当dubbo服务(即生产者)发布之后,我们可以通过telnet命令来来进行调试和管理,以及跟踪服务调用的次数. 注意:2.0.5以上版本服务提供端口支持telnet命令,协议一 ...
- UITouch 的主要方法:
1. UITouch 的主要方法: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesM ...
- Swift-Debug下打印函数名和行数
1.Build Settings ->搜索 Swift compiler -> OTHER_SWIFT_FLAGS = -D DEBUG 2.设置DEBUG函数 配置好后就可以愉快的进行调 ...
- poj_3461 kmp
题目大意 给定两个字符串S1, S2,求S1中包含多少个S2串.其中S1长度最大为 1000000, S2长度最大为10000. 题目分析 典型的字符串匹配问题,直接匹配显然会超时,考虑使用kmp算法 ...
- MUI ajax数据请求(list)
服务器返回格式 { "code": "1001", "message": "查询成功", "data" ...
- java高级---->Thread之BlockingQueue的使用
今天我们通过实例来学习一下BlockingQueue的用法.梦想,可以天花乱坠,理想,是我们一步一个脚印踩出来的坎坷道路. BlockingQueue的实例 官方文档上的对于BlockingQueue ...
- web基础----->模板引擎Velocity的使用(一)
Velocity 是一个基于 Java 的模板引擎框架,提供的模板语言可以使用在 Java 中定义的对象和变量上.今天我们就学习一下Velocity的用法. Velocity的第一个例子 项目的主体是 ...
- LeetCode——Generate Parentheses
Description: Given n pairs of parentheses, write a function to generate all combinations of well-for ...
- Egret Wing4.1.0 断点调试
一 双击代码行号左侧打断点 二 选择调试视图工具栏. 三 点击开始调试 1 wing内置播放器调试 选择此项进行调试会打开Egret内置播放器,我这里这个版本该选项无法进行断点... 2 使用本机 ...