一个数据序列的主元素,是指序列中出现次数超过序列长度一半的元素。法1(期望时间复杂度为O(n)):由于主元素出现次数超过序列长度的一半,因此,主元素一定是中位数。可以利用递归划分求中位数的方法,期望时间复杂度为O(n)。法2:显然,如果一个序列存在主元素,那么我们去掉序列中不同的两个数,剩下序列的主...
分类:
其他好文 时间:
2015-07-28 22:28:41
阅读次数:
135
1 class Solution { 2 public: 3 /** 4 * @param nums: A list of integers. 5 * @return: An integer denotes the middle number of the array....
分类:
其他好文 时间:
2015-07-28 20:56:15
阅读次数:
1220
LintCode - Merge Two Sorted ListsLintCode - Merge Two Sorted Lists
Web Link
Description
Code - C
TipsWeb Linkhttp://www.lintcode.com/en/problem/merge-two-sorted-lists/DescriptionMerge two sorted (ascen...
分类:
其他好文 时间:
2015-07-25 01:50:26
阅读次数:
139
LintCode - Remove Duplicates from Sorted List II Show resultLintCode - Remove Duplicates from Sorted List II Show result
Web Link
Description
Code - C
Tips
Web Linkhttp://www.lintcode.com/en/problem/re...
分类:
其他好文 时间:
2015-07-25 00:13:42
阅读次数:
146
LintCode - Remove Duplicates from Sorted ListLintCode - Remove Duplicates from Sorted List
Web Link
Description
Code - C
Tips
Web Linkhttp://www.lintcode.com/en/problem/remove-duplicates-from-sorted-li...
分类:
其他好文 时间:
2015-07-24 22:45:30
阅读次数:
147
LintCode - Copy List with Random PointerLintCode - Copy List with Random Pointer
Web Link
Description
Code - C
Tips
Web Linkhttp://www.lintcode.com/en/problem/copy-list-with-random-pointer/DescriptionA...
分类:
其他好文 时间:
2015-07-24 18:31:09
阅读次数:
147
LintCode - Add Two Numbers...
分类:
其他好文 时间:
2015-07-24 13:01:04
阅读次数:
143
题目描述
链接地址
解法
算法解释题目描述Given 2*n + 2 numbers, every numbers occurs twice except two, find them.ExampleGiven [1,2,2,3,4,4,5,3] return 1 and 5ChallengeO(n) time, O(1) extra space.
.链接地址http://www.lintcode...
分类:
其他好文 时间:
2015-07-20 23:32:36
阅读次数:
137
Title:有两个不同大小的二进制树:T1有上百万的节点;T2有好几百的节点。请设计一种算法,判定T2是否为T1的子树class Solution {public: /** * @param T1, T2: The roots of binary tree. * @return...
分类:
其他好文 时间:
2015-07-19 23:23:04
阅读次数:
222
题目描述
链接地址
解法
算法解释题目描述Given 2*n + 1 numbers, every numbers occurs twice except one, find it. ExampleGiven [1,2,2,1,3,4,3], return 4链接地址http://www.lintcode.com/en/problem/single-number/解法 int singleNu...
分类:
其他好文 时间:
2015-07-19 20:14:13
阅读次数:
137