Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // DATE: 03-02-2022
- // LINK: https://leetcode.com/problems/maximum-population-year/
- import java.util.*;
- class Solution {
- public int maximumPopulation(int[][] logs) {
- int[] populationYear = new int[1001];
- for(int[] log: logs){
- for(int i=0; i<=(log[1]-1-log[0]);i++){
- populationYear[log[0]-1950+i]+=1;
- }
- }
- int max = Arrays.stream(populationYear).max().getAsInt();
- // return max;
- boolean notFound = true;
- int i=0;
- while(notFound){
- if(populationYear[i] == max){
- notFound = false;
- break;
- }
- i++;
- }
- return 1950+i;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement