链表局部反转问题

代码如下:

class Solution {public ListNode reverseBetween(ListNode head, int m, int n) {if (m == n) return head;ListNode cur = head, pre = null;int cnt = 1;while (cnt < m){if (cnt == m - 1){pre = cur;}cur = cur.next;cnt++;}ListNode p = null;while (cnt <= n){ListNode next = cur.next;cur.next = p;p = cur;cur = next;cnt++;}if (null == pre) {head.next = cur;return p;}else {pre.next.next = cur;pre.next = p;return head;}}
}

LeetCode Reverse Linked List II相关推荐

  1. LeetCode | Reverse Linked List II

    这道链表反转题也是搞的我焦头烂额,好久没有写链表了,注意记忆这些 Reverse Linked List II QuestionEditorial Solution My Submissions To ...

  2. Leetcode: Reverse Linked List II

    Reverse a linked list from position m to n. Do it in-place and in one-pass.For example: Given 1-> ...

  3. [LeetCode] Reverse Linked List II

    Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1-> ...

  4. leetcode : Reverse Linked List II [two pointers]

    Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1-> ...

  5. LeetCode Reverse Linked List II 反置链表2

    题意:将指定的一段位置[m,n]的链表反置,返回链表头. 思路:主要麻烦在链表头,如果要从链表头就开始,比较特殊. 目前用DFS实现,先找到m-1的位置,再找到n+1的位置,中间这段就是否要反置的,交 ...

  6. 【??链表】LeetCode 92. Reverse Linked List II

    LeetCode 92. Reverse Linked List II Solution1: 参考网址:http://www.cnblogs.com/grandyang/p/4306611.html ...

  7. LeetCode 92. Reverse Linked List II

    92. Reverse Linked List II Reverse a linked list from position m to n. Do it in one-pass. 将位置m的链接列表反 ...

  8. (LeetCode 92)Reverse Linked List II

    Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1-> ...

  9. Reverse Linked List II leetcode java

    题目: Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1 ...

最新文章

  1. 这位挺身而出的研究生,被直接录用!
  2. 入职地府后我成了人生赢家_【200811推文】闪闪而恋作者:钦点废柴+入职地府后我成了人生赢家作者:有只胖头鱼...
  3. 布道微服务_06微服务调用的监控
  4. [19/04/23-星期二] GOF23_创建型模式(工厂模式、抽象工厂模式)
  5. python中id函数的用法_用id函数做几个测试
  6. MySQL MVCC 概述
  7. 首页终于让百度放出来了
  8. html轮播图水平传送带,经典的白富美型jQuery图片轮播插件
  9. 09 Softmax回归+损失函数
  10. C#中pdf转word
  11. svn update出现database is locked
  12. 欢迎来到咆哮2020:人工智能时代
  13. Hacking JWT(JSON Web Token)
  14. 实战新浪微博、腾讯微博的分享功能
  15. cd linux 新增分区,目前国内最完整详细的 CDlinux 硬盘安装手册
  16. Win10 C盘爆红找出edb文件146G,删除后又出现如何解决
  17. SAP HANA 2.0 快速版 (虚拟机方法)的部署和使用
  18. 交通物流模型 | Python实现基于张量分解的交通流量时空模式挖掘(出租车车载GPS数据、公交卡刷卡数据、POI的分布数据)
  19. 勤哲服务器 网页填报,勤哲excel服务器按条件提示必填|必填条件_勤哲App应用之家...
  20. 【ML on Kubernetes】第 4 章:机器学习平台剖析

热门文章

  1. [MySQL FAQ]系列 -- Too many open files
  2. nyoj-66 分数拆分
  3. 360下载的mysql_MySQL数据库5.7
  4. python官网安装步骤-新手Windows下Python下载安装教程及配置注意事项
  5. 学会python之后-学会Python后,人生简直开挂了!
  6. 简单python画圣诞树图片-圣诞节!教你用 Python 画棵圣诞树
  7. 如何用python画圆形的代码-python – 如何快速绘制数千个圆圈?
  8. 从零开始学习python-从零开始学python
  9. 笨方法学python3-笨办法学python3 pdf下载|
  10. python和c学习-学习 Python与C相互调用