[프로그래머스] 단속 카메라 - 파이썬/그리디

JinUk Lee·2023년 3월 20일
0

프로그래머스

목록 보기
23/47

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


def solution(routes):
    answer = 0

    routes.sort(key=lambda x:(x[1]))

    max_num = -40000

    for i in routes:
        if max_num >= i[0]:
            continue
        else:
            answer+=1
            max_num = i[1]


    return answer

나가는 위치로 routes를 정렬한다.

나가는 위치를 카메라 설치 위치로 생각하고 반복을 통해 크기 비교를 한다.

조건이 성립되면 +1, 아닐경우 다음 반복으로 continue

profile
개발자 지망생

0개의 댓글