Created
July 30, 2025 07:17
-
-
Save inspirit941/d3d758304f8b368a9331489396b0eafe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def solution(targets): | |
| targets = sorted(targets, key=(lambda x: (x[0], x[1]))) | |
| # 겹치는 구간을 최대한 찾되, 더 이상 겹치는 구간이 없어지면 포를 쏴야만 한다. | |
| start, end = targets[0][0], targets[0][1] | |
| answer = 1 | |
| for idx in range(1, len(targets)): | |
| # 겹치는 범위가 없다면, answer ++ 한 뒤 start, end 초기화한다 | |
| if end <= targets[idx][0]: | |
| answer += 1 | |
| start, end = targets[idx][0], targets[idx][1] | |
| # 공통범위가 있다면, 공통범위로 좁힌다. | |
| start = max(start, targets[idx][0]) | |
| end = min(end, targets[idx][1]) | |
| return answer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment