| [ Web Proxy ] |
| Viewing: https://raw.githubusercontent.com/feixiangcode/algorithm/master/Week_04/id_1/LeetCode_169_1.java | [Back] [Original] |
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeMap;
class Solution {
public int majorityElement(int[] nums) {
HashMap map = new HashMap();
int length = nums.length;
for (int i = 0; i < length; i ++) {
int times = map.getOrDefault(nums[i], 0) + 1;
if (times > length/2) {
return nums[i];
}
map.put(nums[i], times);
}
return 0;
}
}
| Web Proxy Viewer | New URL | Original Page |