13

leetCode解题报告之Sort List

 4 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.
neoserver,ios ssh client
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的代码:


Recommend

  • 9

    leetCode解题报告之构造二叉树(递归)_快乐de胖虎-CSDN博客此博文主要讲述了构造二叉树的两种方法: 1、通过先序和中序构造出二叉树( 来自leetCode OJ上的 题目:

  • 9
    • blog.csdn.net 4 years ago
    • Cache

    leetCode解题报告之Reorder List

    leetCode解题报告之Reorder List_快乐de胖虎-CSDN博客 题目: Given a singly linked list L: L0→L1→…→Ln-1→Ln,...

  • 10
    • blog.csdn.net 4 years ago
    • Cache

    leetCode解题报告5道题(一)

    比较简单的几道题,不做详细的解释,只为之后可以回头看看自己之前的代码!! 虽然几道题都比较简单,但感觉自己写得不好,希望博文如果被哪位大神看到,可以留言下写下你的做法! 题目一: Reverse Linked List II Reverse a link...

  • 8

    leetCode解题报告之O(n)线性时间求最大子序列和(Maximum Subarray)

  • 14

    leetCode解题报告之SingleNumberI,II(知识点:位运算)_快乐de胖虎-CSDN博客由于两题是姐妹题,所以放在同一个博文里了! 题目1: Given an array of integers, every element appears twice except for one. Find that single...

  • 9

    leetCode解题报告之Copy List with Random Pointer_快乐de胖虎-CSDN博客题目: A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. R...

  • 9
    • blog.csdn.net 4 years ago
    • Cache

    leetCode解题报告5道题(十)

    题目一:Valid Number Validate if a given string is numeric. Some examples:"0" => true" 0.1 " => true"abc" => false

  • 10
    • blog.csdn.net 4 years ago
    • Cache

    leetCode解题报告5道题(九)

    题目一:Combinations Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For example, If n = 4 and k = 2, a solution is: [ [2,4], [3,4], [2,3],...

  • 7
    • blog.csdn.net 4 years ago
    • Cache

    leetCode解题报告5道题(十一)

    题目一:Subsets Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be in non-descending order.The solution set must not cont...

  • 8

    leetCode解题报告之Insertion Sort List_快乐de胖虎-CSDN博客题目: Sort a linked list using insertion sort. 分析: 这个题目是想要让我们来做一个链表的插入排序问题. 这样,我们只要从...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK