首页 > 其他 > 详细

24. Swap Nodes in Pairs

时间:2016-04-17 06:45:18      阅读:77      评论:0      收藏:0      [点我收藏+]
    /*
     * 24. Swap Nodes in Pairs 
     * 11.25 by Mingyang
     * 直接强行换
     */
     public ListNode swapPairs(ListNode head) {
            if(head==null)
              return null;
            ListNode pre=new ListNode(-1);
            pre.next=head;
            ListNode res=pre;
            ListNode run=head;
            while(run!=null&&run.next!=null){
                ListNode temp=run.next;
                pre.next=temp;
                run.next=temp.next;
                temp.next=run;
                pre=run;
                run=run.next;
            }
            return res.next;
        }

 

24. Swap Nodes in Pairs

原文:http://www.cnblogs.com/zmyvszk/p/5400178.html

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