Skip to content

Commit e521241

Browse files
authored
Create Maximum Population Year.java
1 parent e6261aa commit e521241

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Easy/Maximum Population Year.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int maximumPopulation(int[][] logs) {
3+
int[] population = new int[2051];
4+
for (int[] log : logs) {
5+
population[log[0]]++;
6+
population[log[1]]--;
7+
}
8+
int maxPopulationYear = 0;
9+
for (int i = 1950; i <= 2050; i++) {
10+
population[i] += population[i - 1];
11+
maxPopulationYear = population[i] > population[maxPopulationYear] ? i : maxPopulationYear;
12+
}
13+
return maxPopulationYear;
14+
}
15+
}

0 commit comments

Comments
 (0)