首页 > 其他 > 详细

92. Reverse Linked List II

时间:2017-09-28 13:45:05      阅读:211      评论:0      收藏:0      [点我收藏+]
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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!