suleesulee
suleesulee
suleesulee
전체 방문자
오늘
어제
  • 분류 전체보기 (39)
    • Personal (7)
      • 개발자sulee (2)
      • 회고록 (1)
      • 여행 (0)
    • Computer Science (31)
      • JAVA (4)
      • Python (0)
      • Html&CSS (0)
      • Spring (1)
      • JPA (1)
      • MSA (12)
      • Algorithm (10)
      • DevOps (0)
      • Go (1)
      • Swift (1)
      • 기타 (1)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

  • 개발자 sulee의 블로그입니다.

인기 글

태그

  • 회고
  • 나의 재취업 도전기
  • 카카오
  • 라인
  • 백엔드
  • 이직뽀개기
  • SOA
  • 네이버
  • 전문연
  • 개발자
  • 이직
  • 전문연구요원
  • Monolithic
  • MSA

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
suleesulee

suleesulee

Computer Science/Algorithm

[리트코드]1854. Maximum Population Year

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)이라 성능은 좋지 않다. 

저작자표시 비영리 변경금지 (새창열림)

'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
    'Computer Science/Algorithm' 카테고리의 다른 글
    • [리트코드]172. Factorial Trailing Zeroes
    • [리트코드]45. Jump Game II
    • [리트코드]1002. Find Common Characters
    • [리트코드]740. Delete and Earn
    suleesulee
    suleesulee
    IT Engineer, SW Developer, Traveler

    티스토리툴바