public static ListNode reverseBetween(ListNode head, int m, int n) {
ListNode pre=head,current=head,mPre = new ListNode(0),mNode = new ListNode(0),nNode = new ListNode(0),temp;
mPre.next=head;
int i=1;
while(i<=n)
{
if(i==m-1)
mPre=current;
if(i==m)
mNode=current;
if(i==n)
nNode=current;
if(m<i&&i<=n)
{
temp=current;
current=current.next;
temp.next=pre;
pre=temp;
}
else{
pre=current;
current=current.next;
}
i++;
}
mPre.next=nNode;
mNode.next=current;
if(m==1)
return nNode;
else
return head; }

Reverse Linked List II java的更多相关文章

  1. leetcode 92 Reverse Linked List II ----- java

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

  2. 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- ...

  3. LeetCode 92. 反转链表 II(Reverse Linked List II)

    92. 反转链表 II 92. Reverse Linked List II 题目描述 反转从位置 m 到 n 的链表.请使用一趟扫描完成反转. 说明: 1 ≤ m ≤ n ≤ 链表长度. LeetC ...

  4. 【leetcode】Reverse Linked List II

    Reverse Linked List II Reverse a linked list from position m to n. Do it in-place and in one-pass. F ...

  5. 14. Reverse Linked List II

    Reverse Linked List II Reverse a linked list from position m to n. Do it in-place and in one-pass. F ...

  6. 【原创】Leetcode -- Reverse Linked List II -- 代码随笔(备忘)

    题目:Reverse Linked List II 题意:Reverse a linked list from position m to n. Do it in-place and in one-p ...

  7. lc面试准备:Reverse Linked List II

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

  8. 【LeetCode练习题】Reverse Linked List II

    Reverse Linked List II Reverse a linked list from position m to n. Do it in-place and in one-pass. F ...

  9. [Linked List]Reverse Linked List,Reverse Linked List II

    一.Reverse Linked List  (M) Reverse Linked List II (M) Binary Tree Upside Down (E) Palindrome Linked ...

随机推荐

  1. GridView+ZedGraph【转】

    edgraph图表控件的强大功能令人出乎意料,与OWC相比我想应该毫不逊色,近来需求要求作出相关数据统计,不想使用BI这类的强大东西,所以搜索到 了免费的开源的Zedgraph控件.使用起来也非常方便 ...

  2. uva 1594 Ducci Sequence <queue,map>

    Ducci Sequence Description   A Ducci sequence is a sequence of n-tuples of integers. Given an n-tupl ...

  3. n个数的最大公约、最小公倍数

    #include <cstdio> #include <cstring> using namespace std; #define N 1010 //两个数的最大公约数和最小公 ...

  4. NSInteger和BOOL的底层类型

    在Objective-C中,NSInteger和BOOL是通过typedef或者#define宏进行定义的,那么,这两个数据类型的底层类型是什么呢? 首先查看NSInteger的定义: #if __L ...

  5. oracle 联表更新

    依 a 表 cate_pub_id  为依据 更新 v 表的 cate_pub_id update td_tobrel_cate_pub_attrval v set v.CATE_PUB_ID=(se ...

  6. 【solr专题之三】Solr常见异常

    1.RemoteSolrException: Expected mime type application/octet-stream but got text/html 现象: SLF4J: Fail ...

  7. 创建ListView的基本步骤

    参考<疯狂android讲义>第2.5节P94 1.创建一个或者多个ListView <LinearLayout xmlns:android="http://schemas ...

  8. 十进制二进制之间的转化 PHP算法

    [ 十进制转二进制 ] function test($var){ $func = function($i){ if($i < 2){ return $i; } $return['int'] = ...

  9. Keil中如何消除UNCALLED SEGMENT,IGNORED FOR OVERLAY PROCESS警告

    在Keil C中,如果没有显式调用到定义过的函数,就会出现这样的的警告.当出现这样的警告时,可以不用管,因为不影响其它部分.但是,我们知道,即使没有调用这个函数,Keil仍然把它编译连接进整个程序,不 ...

  10. C语言预处理命令总结大全

    C程序的源代码中可包括各种编译指令,这些指令称为预处理命令.虽然它们实际上不是C语言的一部分,但却扩展了C程序设计的环境.本节将介绍如何应用预处理程序和注释简化程序开发过程,并提高程序的可读性.ANS ...