S*******C 发帖数: 822 | 1 Majority Number II
34%
Accepted
Given an array of integers, the majority number is the number that occurs
more than 1/3 of the size of the array.
Find it.
Note
There is only one majority number in the array
Example
For [1, 2, 1, 2, 1, 3, 3] return 1
Challenge
O(n) time and O(1) space
public class Solution {
/**
* @param nums: A list of integers
* @return: The majority number that occurs more than 1/3
*/
public int majorityNumber(ArrayList nums) {
// write your code
}
}
http://lintcode.com/en/problem/majority-number-ii/ |
|