package com.算法专练.力扣.人口最多的年份;
import java.util.HashMap;
import java.util.Map;
/**
* @author xnl
* @Description:
* @date: 2022/8/21 21:27
*/
public class Solution {
public static void main(String[] args) {
Solution solution = new Solution();
// int[][] logs = {{1993,1999},{2000,2010}};
int[][] logs = {{1950,1961},{1960,1971},{1970,1981}};
System.out.println(solution.maximumPopulation(logs));
}
int offerSett = 1950;
public int maximumPopulation(int[][] logs) {
int[] delta = new int[101];
for (int[] log : logs) {
delta[log[0] - offerSett]++;
delta[log[1] - offerSett]--;
}
int mx = 0, res = 0, curr = 0;
for (int i = 0 ;i < 101; i++){
curr += delta[i];
if (curr > mx){
mx = curr;
res = i;
}
}
return res + offerSett;
}
}
差分数组

1万+

被折叠的 条评论
为什么被折叠?



