Skip to content

Commit 02c8a7f

Browse files
committed
Time: 15 ms (28.5%), Space: 53.3 MB (13.7%) - LeetHub
1 parent b28251a commit 02c8a7f

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public List<Integer> majorityElement(int[] nums) {
3+
int limit = nums.length/3 + 1;
4+
List<Integer> res = new ArrayList<>();
5+
HashMap<Integer,Integer> freq = new HashMap<>();
6+
for(int i : nums){
7+
freq.put(i, freq.getOrDefault(i,0)+1);
8+
}
9+
10+
for(int i : freq.keySet()){
11+
if(freq.get(i) >= limit ){
12+
res.add(i);
13+
}
14+
}
15+
return res;
16+
}
17+
}

0 commit comments

Comments
 (0)