码迷,mamicode.com
首页 > 其他好文 > 详细

92. Reverse Linked List II

时间:2017-09-28 14:16:52      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:color   pre   blog   nbsp   col   between   ++   link   head   

class Solution {
    public ListNode reverseBetween(ListNode head, int m, int n) {
        ListNode pre=new ListNode(0);
        pre.next=head;
        ListNode p=pre;
        for(int i=0;i<m-1;i++)
            p=p.next;
        int s=n-m;
        ListNode q=p.next;
        while(s>0)
        {
            ListNode r=q.next;
            q.next=q.next.next;
            r.next=p.next;
            p.next=r;
            s--;
        }
        return pre.next;
    }
}

 

92. Reverse Linked List II

标签:color   pre   blog   nbsp   col   between   ++   link   head   

原文地址:http://www.cnblogs.com/asuran/p/7606275.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!