646. Maximum Length of Pair Chain Medium

@problem@discussion
#Array#Dynamic Programming#Greedy#Sorting



1/**
2 * [646] Maximum Length of Pair Chain
3 *
4 * You are given an array of n pairs pairs where pairs[i] = [lefti, righti] and lefti < righti.
5 * A pair p2 = [c, d] follows a pair p1 = [a, b] if b < c. A chain of pairs can be formed in this fashion.
6 * Return the length longest chain which can be formed.
7 * You do not need to use up all the given intervals. You can select pairs in any order.
8 *  
9 * Example 1:
10 * 
11 * Input: pairs = [[1,2],[2,3],[3,4]]
12 * Output: 2
13 * Explanation: The longest chain is [1,2] -> [3,4].
14 * 
15 * Example 2:
16 * 
17 * Input: pairs = [[1,2],[7,8],[4,5]]
18 * Output: 3
19 * Explanation: The longest chain is [1,2] -> [4,5] -> [7,8].
20 * 
21 *  
22 * Constraints:
23 * 
24 * 	n == pairs.length
25 * 	1 <= n <= 1000
26 * 	-1000 <= lefti < righti <= 1000
27 * 
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/maximum-length-of-pair-chain/
32// discuss: https://leetcode.com/problems/maximum-length-of-pair-chain/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37    pub fn find_longest_chain(pairs: Vec<Vec<i32>>) -> i32 {
38        0
39    }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_646() {
50    }
51}
52


Back
© 2025 bowen.ge All Rights Reserved.