Skip to content

Commit d48f7db

Browse files
add 1854
1 parent b9b93d8 commit d48f7db

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1854|[Maximum Population Year](https://leetcode.com/problems/maximum-population-year/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1854.java) ||Easy|Array|
1112
|1848|[Minimum Distance to the Target Element](https://leetcode.com/problems/minimum-distance-to-the-target-element/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1848.java) ||Easy|Array|
1213
|1845|[Seat Reservation Manager](https://leetcode.com/problems/seat-reservation-manager/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1845.java) ||Medium|Heap, Design|
1314
|1844|[Replace All Digits with Characters](https://leetcode.com/problems/replace-all-digits-with-characters/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1844.java) ||Easy|String|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.TreeMap;
4+
5+
public class _1854 {
6+
public static class Solution1 {
7+
public int maximumPopulation(int[][] logs) {
8+
TreeMap<Integer, Integer> map = new TreeMap<>();
9+
for (int[] log : logs) {
10+
for (int start = log[0]; start < log[1]; start++) {
11+
map.put(start, map.getOrDefault(start, 0) + 1);
12+
}
13+
}
14+
int maxPop = 0;
15+
int maxPopYear = 0;
16+
for (int year : map.keySet()) {
17+
if (map.get(year) > maxPop) {
18+
maxPop = map.get(year);
19+
maxPopYear = year;
20+
}
21+
}
22+
return maxPopYear;
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)