Computer Science/Algorithm
[리트코드]1854. Maximum Population Year
suleesulee
2021. 9. 6. 20:27
class Solution:
def maximumPopulation(self, logs: List[List[int]]) -> int:
max_year = -1e9
min_year = 1e9
max_po = 0
ye = 0
for i in range(len(logs)):
if min_year > logs[i][0]:
min_year = logs[i][0]
if max_year < logs[i][1]:
max_year = logs[i][1]
for i in range(min_year, max_year):
cnt = 0
for j in range(len(logs)):
if logs[j][0] <= i and i < logs[j][1] :
cnt += 1
if max_po < cnt:
max_po = cnt
ye = i
return ye
난이도 Easy
초기, 끝 년도를 구한 뒤 범위에 포함되나 하나씩 비교해봄
O(n^2)이라 성능은 좋지 않다.