Skip to content

Instantly share code, notes, and snippets.

@inspirit941
Created July 30, 2025 07:17
Show Gist options
  • Select an option

  • Save inspirit941/d3d758304f8b368a9331489396b0eafe to your computer and use it in GitHub Desktop.

Select an option

Save inspirit941/d3d758304f8b368a9331489396b0eafe to your computer and use it in GitHub Desktop.
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