728x90
😉 아이디어
- _!이전 차량의 종료위치 < 현재 차량의 시작위치!_ 일 경우에 카메라 추가
- _!end!_ 기준으로 정렬하면 _!end!_ 이전에 모든 경로를 통틀어 1개의 카메라로 취급가능
😉 풀이
def solution(routes):
answer = 0
routes.sort(key = lambda x : (x[1]))
print('routes', routes)
prev = [-30_001, -30_001]
for route in routes:
start, end = route
# prev 내에서 단 1개만 필요 -> 범위가 벗어날 경우만 카메라 추가
if prev[1] < start:
print(f'상승 route = {route}')
answer += 1
prev = route
return answer
✔ 링크 : https://school.programmers.co.kr/learn/courses/30/lessons/42884#