当前位置:网站首页>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;
}
}
边栏推荐
- regular
- SSH服务突然连接不了案例总结
- Is there a free and commercially available website for US media video clips?
- Learn the calculation method of quantile value in n minutes
- Analysis of ISP one click download principle in stm32
- Leetcode-81. search rotation sort array II (binary search returns true/false)
- [rust] reference and borrowing, string slice type (& STR) - rust language foundation 12
- 【C语言】动态内存管理
- Buckle practice - 30 set the intersection size to at least 2
- 2022.07.15 暑假集训 个人排位赛(十)
猜你喜欢

Zabbix5.0.8-odbc monitoring Oracle11g
![[function test] test of the project - login and post function](/img/64/c9bbf34964622f4f013b1184eeb1e0.jpg)
[function test] test of the project - login and post function

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

Getting started with SQL join use examples to learn left connection, inner connection and self connection

thinkphp 实现数据库备份

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

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

Leetcode's 302 weekly rematch

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

SSM online rental and sales platform multi city version
随机推荐
深圳地铁12号线第二批工程验收通过 预计7月28日试运行
Get the current month and year and the previous 11 months
Custom scroll bar
nacos部署
No routines, no traps, no advertisements | are you sure you don't need this free instant messaging software?
I used annotations to configure the serialization of redis in one module project, and then introduced this module in another module. Why is this configuration
The second batch of projects of Shenzhen Metro Line 12 passed the acceptance and is expected to be put into trial operation on July 28
Leecode-268. missing numbers (Application of XOR, find numbers that do not appear, find numbers that only appear once)
Getting started with SQL join use examples to learn left connection, inner connection and self connection
ERROR: [Synth 8-439] module ‘xxx‘ not found not found 错误解决办法
SSM在线租房售房平台多城市版本
Support liuhaiping
Installation and deployment of ansible
Is it safe to open an account on Oriental Fortune online? Is there a threshold for opening an account?
Take chef and ansible as examples to get started with server configuration
iSCSI新应用,以及NFS的存储服务分离
English语法_不定代词 - 概述
1.9. 触摸按钮(touch pad)测试
Is it safe for Huatai Securities to open a remote account? Is there any guarantee?
Solutions to problems in IE6 browser