-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem.java
More file actions
32 lines (26 loc) · 808 Bytes
/
Copy pathProblem.java
File metadata and controls
32 lines (26 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package Java;
import java.util.*;
public class Problem{
@SuppressWarnings("unused")
private static int Value;
public static void majourElement(int[] num){
HashMap<Integer,Integer> map=new HashMap<>();
int n=num.length;
for(int i=0;i<n;i++){
if(map.containsKey(num[i])){
map.put((num[i]),map.get(num[i])+1);
}else{
map.put(num[i],Value=1);
}
for(int key:map.keySet()){
if(map.get(key)>n/3){
System.out.println(key);
}
}
}
}
public static void main(String[] args){
int num[] = {1,3,2,5,2,3,3,2};
majourElement(num);
}
}