Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋
times.
You may assume that the array is non-empty and the majority element always exist in the array.
又是大神级别算法,O(n) time O(1) space fastest solution,比快排一遍找中位数还要快。。给跪
|
|
顺便附上证明论文:
http://www.cs.utexas.edu/~moore/best-ideas/mjrty/
虽然我知道你们肯定没人看的。
近期评论