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)이라 성능은 좋지 않다.
'Computer Science > Algorithm' 카테고리의 다른 글
[리트코드]172. Factorial Trailing Zeroes (0) | 2021.09.07 |
---|---|
[리트코드]45. Jump Game II (0) | 2021.09.06 |
[리트코드]1002. Find Common Characters (0) | 2021.09.06 |
[리트코드]740. Delete and Earn (0) | 2021.09.03 |
[리트코드]18. 4Sum (0) | 2021.09.03 |