[level 3] Title: 단속카메라, Time: 0.86 ms, Memory: 10.5 MB -BaekjoonHub

This commit is contained in:
SSUM
2025-03-08 12:02:38 +09:00
parent f45849bd0a
commit 509c13cc9b
2 changed files with 7 additions and 10 deletions

View File

@@ -4,7 +4,7 @@
### 성능 요약
메모리: 10.5 MB, 시간: 0.88 ms
메모리: 10.5 MB, 시간: 0.86 ms
### 구분
@@ -16,7 +16,7 @@
### 제출 일자
2025년 03월 0723:18:16
2025년 03월 0812:02:35
### 문제 설명

View File

@@ -1,15 +1,12 @@
def solution(routes):
# 종료 지점을 기준으로 정렬합니다.
routes.sort(key=lambda x: x[1])
routes.sort(key = lambda x:x[1])
count = 0 # 설치한 카메라 수
camera = -30001 # 초기 카메라 위치 (최소 진입 지점보다 작은 값으로 설정)
camera = -30001
count = 0
for s, e in routes:
# 현재 차량의 진입 지점이 현재 카메라 위치보다 크다면,
# 현재 카메라로 커버할 수 없으므로, 새로운 카메라를 해당 차량의 진출 지점에 설치합니다.
if s > camera:
if camera < s:
count += 1
camera = e
return count