public class Solution {
public int majorityElement(int[] nums) {
int result = nums[0];
int count = 1;
for (int i = 1; i < nums.length; i++) {
if (nums[i] == result) {
count++;
} else {
count--;
}
if (count == 0) {
result = nums[i + 1];
}
}
return result;
}
}
Majority Element
最新推荐文章于 2016-07-23 22:38:02 发布