L2 : 단속카메라 Python

jhyunn·2023년 1월 20일
0

Programmers

목록 보기
49/69

L2 : 단속카메라 Python

https://school.programmers.co.kr/learn/courses/30/lessons/42884

def solution(routes):
    routes.sort(key=lambda x: x[1]) # 끝나는 지점을 기준으로 정렬
    camera = routes[0][1] # 탈출 지점에 카메라 설치
    cnt = 1
    for i in range(1, len(routes)):
        if routes[i][0] <= camera: # 다음 루트가 카메라를 포함하면 패스
            continue
        else: # 다음 루트에 카메라가 없으면 해당 루트 끝에 카메라 설치
            camera = routes[i][1]
            cnt += 1
    return cnt

#greedy #그리디

profile
https://github.com/Sungjeonghyun

0개의 댓글