Sort a linked list in O(n log n)
time using constant space complexity.
MergeSort对于链表的排序,实现了就地排序的同时,时间复杂度和空间复杂度都达到了基于比较的排序的最优值,因此归并排序是链表排序的最佳排序方式。
/**
* Definition for singly-linked list.
* str...
分类:
其他好文 时间:
2015-01-15 16:01:52
阅读次数:
193
Factorial Trailing ZeroesGiven an integern, return the number of trailing zeroes inn!.Note:Your solution should be in logarithmic time complexity.思路:不...
分类:
其他好文 时间:
2015-01-15 15:57:13
阅读次数:
158
Given an array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using ext...
分类:
其他好文 时间:
2015-01-15 11:05:40
阅读次数:
207
Given an array of integers, every element appears three times except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without usi...
分类:
其他好文 时间:
2015-01-15 11:03:15
阅读次数:
157
Given an array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using ext...
分类:
其他好文 时间:
2015-01-14 23:01:20
阅读次数:
402
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be ...
分类:
其他好文 时间:
2015-01-14 00:42:38
阅读次数:
278
问题描述:
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
代码:
public ListNode mergeTwoLists(ListNode l1, ListNode l2) { //java
if(l2 == nu...
分类:
其他好文 时间:
2015-01-13 21:34:54
阅读次数:
193
Sort a linked list in O(n log n)
time using constant space complexity.
#include
#include
typedef struct ListNode{
int val;
struct ListNode *next;
}ListNode;
ListNode *mergesort(ListNode *...
分类:
其他好文 时间:
2015-01-13 17:42:46
阅读次数:
113
Follow up for "Search in Rotated Sorted Array":
What if duplicates are allowed?
Would this affect the run-time complexity? How and why?
Write a function to determine if a given target is in the...
分类:
其他好文 时间:
2015-01-13 12:33:11
阅读次数:
118
LeetCode172——Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
难度系数:容易
题目大意:给定一个整数n,...
分类:
其他好文 时间:
2015-01-13 01:27:55
阅读次数:
142