Conversation
[646] Maximum Length of Pair Chain
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[646] Maximum Length of Pair Chain
문제 설명
You are given an array of
npairspairswherepairs[i] = [lefti, righti]andlefti < righti.A pair
p2 = [c, d]follows a pairp1 = [a, b]ifb < c. A chain of pairs can be formed in this fashion.Return the length longest chain which can be formed.
You do not need to use up all the given intervals. You can select pairs in any order.
Example 1:
Example 2:
코드 설명
우리는 가능한 한 빨리 끝나는 구간을 먼저 선택해야
→ 이후 더 많은 구간을 붙일 수 있음
체인의 길이
마지막으로 선택된 pair의 끝 값
처음엔 어떤 값도 선택하지 않았으므로
가장 작은 값으로 설정
정렬된 배열을 순차 탐색
이전 pair의 끝 < 현재 pair의 시작
체인 길이 증가
새로 선택한 pair의 끝값으로 갱신
최종 체인 길이 반환