Maximum Population Year LeetCode solution in C++

1
class Solution {
2
public:
3
int maximumPopulation(vector<vector<int>> &logs) {
4
int arr[101] = {0};
5
for (vector<int> log : logs) {
6
arr[log[0] - 1950]++;
7
arr[log[1] - 1950]--;
8
}
9
int max = 0, year, cnt = 0;
10
for (int i = 0; i < 101; i++) {
11
cnt += arr[i];
12
if (cnt > max) max = cnt, year = i;
13
}
14
return year + 1950;
15
}
16
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0