-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMigratoryBirds.java
More file actions
32 lines (31 loc) · 843 Bytes
/
MigratoryBirds.java
File metadata and controls
32 lines (31 loc) · 843 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
32
public static int migratoryBirds(List<Integer> arr) {
int[] idArray = new int[5];
int max = idArray[0];
int index = 0;
for (int element: arr) {
switch (element) {
case 1:
idArray[0]++;
break;
case 2:
idArray[1]++;
break;
case 3:
idArray[2]++;
break;
case 4:
idArray[3]++;
break;
case 5:
idArray[4]++;
break;
}
}
for (int i = 0; i < 5; i++) {
if (idArray[i] > max) {
max = idArray[i];
index = i + 1;
}
}
return index;
}