# 0646. Maximum Length of Pair Chain ###### tags: `Leetcode` `Medium` `Greedy` `Intervals` Link: https://leetcode.com/problems/maximum-length-of-pair-chain/description/ ## 思路 和[0435. Non-overlapping Intervals](https://hackmd.io/uFsAyMtgTiGM9LE-8ycrqA)几乎一样 ## Code ```java= class Solution { public int findLongestChain(int[][] pairs) { Arrays.sort(pairs, (a,b)->(a[1]-b[1])); int idx = 1; int cnt = 0; int end = pairs[0][1]; int n = pairs.length; while(idx<n){ while(idx<n && end>=pairs[idx][0]){ idx++; cnt++; } if(idx!=n) end = pairs[idx][1]; idx++; } return n-cnt; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up