-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMigratory Birds.java
More file actions
46 lines (38 loc) · 1.13 KB
/
Migratory Birds.java
File metadata and controls
46 lines (38 loc) · 1.13 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.Scanner;
import java.util.TreeMap;
import java.util.ArrayList;
class Main{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
TreeMap<Integer,Integer> map=new TreeMap<>();
ArrayList<Integer> set=new ArrayList<>();
while(sc.hasNext()){
if(sc.hasNextInt()){
int x=sc.nextInt();
if(map.containsKey(x))
{
map.put(x,map.get(x)+1);
}
else
{
map.put(x,1);
}
}
else
{
sc.next();
}
}
for(int i:map.keySet())
{
set.add(i);
}
for(int i=0;i<set.size()-1;i++){
if(map.get(set.get(i))>=map.get(set.get(i+1)))
{
System.out.println(set.get(i));
return;
}
}
}
}