adding old solved challenges
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BirdsMigration {
|
||||
public static void main(String[] args) {
|
||||
|
||||
List<Integer> BirdType = new ArrayList<>();
|
||||
BirdType.add(1);
|
||||
BirdType.add(3);
|
||||
BirdType.add(3);
|
||||
BirdType.add(2);
|
||||
BirdType.add(2);
|
||||
BirdType.add(2);
|
||||
|
||||
System.out.println(smallestID(BirdType));
|
||||
|
||||
}
|
||||
|
||||
private static int smallestID(List<Integer> birds) {
|
||||
int[] birdsTypeId = new int[6];
|
||||
int max = 0;
|
||||
|
||||
for (int bird : birds) {
|
||||
birdsTypeId[bird]++;
|
||||
max = Math.max(max, birdsTypeId[bird]);
|
||||
}
|
||||
for (int i = 0; i < birdsTypeId.length; i++) {
|
||||
if (birdsTypeId[i] == max) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user