11

leetCode解题报告之Sort List

 3 years ago
source link: https://blog.csdn.net/ljphhj/article/details/21317387
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
leetCode解题报告之Sort List_快乐de胖虎-CSDN博客

勉励自己:坚持,谁说做工程的人不能学好算法!为面试做准备,加油!!!!!

题目:

Sort a linked list in O(n log n) time using constant space complexity.

分析:

题目要求我们要用一个复杂度O(nlogn)的排序算法来排序一个链表,复杂度O(nlogn)的排序算法包括:快速排序堆排序,希尔排序,二叉排序树排序归并排序

情况:

考虑到题目的要求,我个人觉得用“归并排序”会比较好!

第一次提交没AC的Time Limit Exceeded代码:(没有考虑到两个递归之后的子链表做排序的话,关于合并的时间消耗)

下面是AC的代码:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK