首页 > 其他 > 详细

Leetcode148-Sort_List

时间:2019-10-24 23:22:23      阅读:104      评论:0      收藏:0      [点我收藏+]

Sort_List

 

冒泡排序(超时了)

public ListNode sortList(ListNode head) {
        
        if(null == head)
            return head;
        
        int counter = 0;
        ListNode current = head;
        while (null != current.next) {
            current = current.next;
            counter++;
        }

        current = head;
        int pre;
        while (counter > 0) {
            for (int i = 0; i < counter; i++) {
                if (current.val > current.next.val) {
                    pre = current.val;
                    current.val = current.next.val;
                    current.next.val = pre;
                }
                current = current.next;
            }
            current = head;
            counter--;
        }
        return head;
        
    }

  

Leetcode148-Sort_List

原文:https://www.cnblogs.com/Jomini/p/11735623.html

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