当前位置:网站首页>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;
}
}
边栏推荐
- Buckle practice - 24 remove repeated letters
- 深圳地铁12号线第二批工程验收通过 预计7月28日试运行
- Error: [synth 8-439] module 'xxx' not found not found error solution
- 1.4.1 many, many symbols (cin/cout unbinding, O3 optimization)
- Wechat applet learning five page Jump methods
- Vscode solves the problem of terminal Chinese garbled code
- Ah, I am uncle card space
- 02 linear structure 2 multiplication and addition of univariate polynomials (linked list solution)
- Generator and async solve asynchronous programming
- Ape anthropology topic 5
猜你喜欢

The price of domestic flagship mobile phones is nearly 6000, but they can't even beat iphone12. It's clear who users choose

高速成长的背后,华为云乌兰察布数据中心的绿色之道

Implementing deep learning framework from zero -- further exploration of the implementation of multilayer bidirectional RNN

Deep and shallow copies of objects, extends

Mobilevit: challenge the end-to-side overlord of mobilenet

Reserved instances & Savings Plans

ASP. Net core deployment Manual: 1. Deployment Basics

Prototype inheritance

基于Kubernetes v1.24.0的集群搭建(一)

自己实现is_default_constructible
随机推荐
Behind the rapid growth, Huawei cloud Wulanchabu data center is the green way
ERROR: [Synth 8-439] module ‘xxx‘ not found not found 错误解决办法
leetcode第 302 场周赛复盘
regular
What kind of experience is a monthly salary of 30000 yuan? Can we achieve this level as we media
ThinkPHP realizes database backup
基于matlab的语音处理
Wechat applet generates QR code
Take chef and ansible as examples to get started with server configuration
How to render millions of 2D objects smoothly with webgpu?
ASP. Net core deployment Manual: 1. Deployment Basics
2022.07.15 暑假集训 个人排位赛(十)
sql的where+or的用法丢失条件
SSM在线租房售房平台多城市版本
How QT creator changes the default build directory
元宇宙更多的功能和作用在于对于传统生活方式和生产方式的深度改造
国产旗舰手机定价近六千,却连iPhone12都打不过,用户选谁很明确
从零实现深度学习框架——再探多层双向RNN的实现
2022.07.15 summer training personal qualifying (10)
Deep and shallow copies of objects, extends