zoukankan      html  css  js  c++  java
  • Reverse Linked List II

     1 public class Solution {
     2     public ListNode reverseBetween(ListNode head, int m, int n) {
     3         // IMPORTANT: Please reset any member data you declared, as
     4         // the same Solution instance will be reused for each test case.
     5         ListNode newhead = new ListNode(0);
     6         
     7         newhead.next = head;
     8         
     9         ListNode runner = newhead;
    10         for(int i = 0; i < m-1; i++)
    11         {
    12             runner = runner.next;
    13         }
    14         ListNode premindex = runner;
    15         ListNode mindex = runner.next;
    16         
    17         ListNode pre = mindex;
    18         runner = mindex.next;
    19         
    20         for(int i = 0; i < n - m; i++)
    21         {
    22             ListNode tmp = runner.next;
    23             runner.next = pre;
    24             pre = runner;
    25             runner = tmp;
    26         }
    27         premindex.next = pre;
    28         mindex.next = runner;
    29         return newhead.next;
    30     }
    31 }
  • 相关阅读:
    poj3411
    2241 排序二叉树
    1004 四子连棋
    Poj1482
    poj2046
    Poj3087
    poj3414
    php使用flock堵塞写入文件和非堵塞写入文件
    HTML样式以及使用
    高效程序猿的狂暴之路
  • 原文地址:https://www.cnblogs.com/jasonC/p/3419330.html
Copyright © 2011-2022 走看看