博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[LeetCode]92. Reverse Linked List II
阅读量:2787 次
发布时间:2019-05-13

本文共 613 字,大约阅读时间需要 2 分钟。

旋转指定起点和终点部分链表

创建一个头结点(这是套路),用cur保存要翻转位置的前一个node,start保存已经反转完成的结尾位置,then保存要翻转的下一位置。

public class Solution {    public ListNode reverseBetween(ListNode head, int m, int n) {        ListNode pre = new ListNode(0);        pre.next = head;        ListNode cur = pre;        for (int i = 0; i < m - 1; i++) {            cur = cur.next;        }        ListNode start = cur.next;        ListNode then = start.next;        for (int i = 0; i < n - m; i++) {            start.next = then.next;            then.next = cur.next;            cur.next = then;            then = start.next;        }        return pre.next;    }}

转载地址:http://fthld.baihongyu.com/

你可能感兴趣的文章
线上故障处理原则
查看>>
技术管理主要做什么?
查看>>
什么才是软件开发中最佳实践呢?
查看>>
大数据平台日志存储分析系统解决方案
查看>>
二叉树的基本操作
查看>>
C语言经典编程题
查看>>
根文件系统树的制作及详解
查看>>
Linux进程间通信
查看>>
什么是solr
查看>>
Pytorch学习要点整理
查看>>
OCR之端到端任意形状的场景文字识别 ICCV2019 End-to-End Text Spotting
查看>>
一种值得借鉴的RPN:GARPN | Region Proposal by Guided Anchoring
查看>>
FAT over NAND Flash
查看>>
(一)802.11无线网络权威指南学习笔记1-3
查看>>
无线Mesh网络的优点总结
查看>>
浅谈原始套接字 SOCK_RAW 的内幕及其应用(port scan, packet sniffer, syn flood, icmp flood)
查看>>
要实现的软件
查看>>
对一名电子信息工程专业应届毕业生的建议 .
查看>>
linux block层的class diagram
查看>>
emmc总结
查看>>