当前位置:网站首页>26. Reverse linked list II
26. Reverse linked list II
2022-07-24 12:46:00 【Little happy】
92. Reverse a linked list II
Give you the head pointer of the single linked list head And two integers left and right , among left <= right . Please reverse from position left To the position right The linked list node of , return Inverted list .
Example 1:

Input :head = [1,2,3,4,5], left = 2, right = 4
Output :[1,4,3,2,5]
Example 2:
Input :head = [5], left = 1, right = 1
Output :[5]


/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * } */
class Solution {
public ListNode reverseBetween(ListNode head, int m, int n) {
ListNode dummy = new ListNode(0);
dummy.next = head;
ListNode p = dummy;
ListNode q = dummy;
for(int i = 0;i < m - 1;i ++) p = p.next;
for(int i = 0;i < n ;i ++) q = q.next;
ListNode a = p.next;
ListNode b = q.next;
for(ListNode c = p.next,d = c.next;d != b;)
{
ListNode e = d.next;
d.next = c;
c = d;
d = e;
}
a.next = b;
p.next = q;
return dummy.next;
}
}
边栏推荐
- Custom scroll bar
- 雪花算法(PHP)
- 突破内存墙能带来什么?看火山引擎智能推荐服务节支增效实战
- SSM在线校园相册管理平台
- 2022.07.15 暑假集训 个人排位赛(十)
- Summary of recent interviews
- 高速成长的背后,华为云乌兰察布数据中心的绿色之道
- Okaleido tiger NFT is about to log in to binance NFT platform
- Analysis of ISP one click download principle in stm32
- Error: [synth 8-439] module 'xxx' not found not found error solution
猜你喜欢

Behind the rapid growth, Huawei cloud Wulanchabu data center is the green way

Qt Creator怎样更改默认构建目录

No routines, no traps, no advertisements | are you sure you don't need this free instant messaging software?

C language course design -- hotel management system
Efficientformer: lightweight vit backbone

Okaleido tiger NFT is about to log in to binance NFT platform

手把手教你用 Power BI 实现 4 种可视化图表

Summary of recent interviews

Okaleido tiger NFT即将登录Binance NFT平台
![Error: [synth 8-439] module 'xxx' not found not found error solution](/img/47/bb03cc26e254332bf815c80bafb243.png)
Error: [synth 8-439] module 'xxx' not found not found error solution
随机推荐
ERROR: [Synth 8-439] module ‘xxx‘ not found not found 错误解决办法
Buckle practice - maximum number of 28 splices
Buckle practice - sum of 34 combinations
Raspberry pie self built NAS cloud disk -- raspberry pie built network storage disk
基于matlab的声音识别
做自媒体视频剪辑有免费可商用的素材网站吗?
使用TypeFace设置TextView的文字字体
sql的where+or的用法丢失条件
2022.07.15 暑假集训 个人排位赛(十)
Correct use of qwaitcondition
SSM在线校园相册管理平台
我在一个模块工程中使用注解配置了redis的序列化, 然后在另外一个模块引入这个模块,为什么这个配置
How to realize the function of grabbing red envelopes in IM system?
SSM医院住院管理系统
Native Crash的一切
3.实现蛇和基本游戏界面
It is difficult for Chinese consumers and industrial chains to leave apple, and iPhone has too much influence
Leecode-268. missing numbers (Application of XOR, find numbers that do not appear, find numbers that only appear once)
Take chef and ansible as examples to get started with server configuration
Cluster construction based on kubernetes v1.24.0 (II)