当前位置:网站首页>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;
}
}
边栏推荐
- Is there a free and commercially available website for US media video clips?
- The price of domestic flagship mobile phones is nearly 6000, but they can't even beat iphone12. It's clear who users choose
- 猿人学第五题
- Native Crash的一切
- More functions and functions of the metauniverse lie in the deep transformation of the traditional way of life and production
- Cluster construction based on kubernetes v1.24.0 (I)
- Reserved instances & Savings Plans
- The seventh topic of ape Anthropology
- 1.9. 触摸按钮(touch pad)测试
- 有没有2、3w前期适合一个人干的创业项目呢?做自媒体可以吗?
猜你喜欢

【Rust】引用和借用,字符串切片 (slice) 类型 (&str)——Rust语言基础12

基于matlab的语音处理

Cluster construction based on kubernetes v1.24.0 (II)

自己实现is_default_constructible

Custom scroll bar

Use abp Zero builds a third-party login module (III): web side development

ASP. Net core deployment Manual: 1. Deployment Basics

Prototype inheritance

ThinkPHP realizes database backup

手把手教你用 Power BI 实现 4 种可视化图表
随机推荐
Raspberry pie self built NAS cloud disk -- raspberry pie built network storage disk
Is there a free and commercially available website for US media video clips?
Custom scroll bar
SSH服务突然连接不了案例总结
Slow motion animation, window related data and operations, BOM operations [DOM (V)]
国产旗舰手机定价近六千,却连iPhone12都打不过,用户选谁很明确
Leetcode-81. search rotation sort array II (binary search returns true/false)
Case summary of SSH service suddenly unable to connect
How to realize the function of grabbing red envelopes in IM system?
Qt Creator怎样更改默认构建目录
EfficientFormer:轻量化ViT Backbone
2022.07.15 暑假集训 个人排位赛(十)
高速成长的背后,华为云乌兰察布数据中心的绿色之道
Set up CI server with Jenkins
[rust] reference and borrowing, string slice type (& STR) - rust language foundation 12
【功能测试】项目的测试——登录和发布文章功能
Take chef and ansible as examples to get started with server configuration
Leetcode's 302 weekly rematch
Buckle practice - 30 set the intersection size to at least 2
Proxy