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

Leetcode148-Sort_List

时间:2019-10-25 00:08:14      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:r++   i++   counter   java   list   排序   int   冒泡排序   nbsp   

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

标签:r++   i++   counter   java   list   排序   int   冒泡排序   nbsp   

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

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