java.lang.Object
g0601_0700.s0646_maximum_length_of_pair_chain.Solution

public class Solution extends Object
646 - Maximum Length of Pair Chain.<p>Medium</p> <p>You are given an array of <code>n</code> pairs <code>pairs</code> where <code>pairs[i] = [left<sub>i</sub>, right<sub>i</sub>]</code> and <code>left<sub>i</sub> < right<sub>i</sub></code>.</p> <p>A pair <code>p2 = [c, d]</code> <strong>follows</strong> a pair <code>p1 = [a, b]</code> if <code>b < c</code>. A <strong>chain</strong> of pairs can be formed in this fashion.</p> <p>Return <em>the length longest chain which can be formed</em>.</p> <p>You do not need to use up all the given intervals. You can select pairs in any order.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> pairs = [[1,2],[2,3],[3,4]]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> The longest chain is [1,2] -> [3,4].</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> pairs = [[1,2],[7,8],[4,5]]</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> The longest chain is [1,2] -> [4,5] -> [7,8].</p> <p><strong>Constraints:</strong></p> <ul> <li><code>n == pairs.length</code></li> <li><code>1 <= n <= 1000</code></li> <li><code>-1000 <= left<sub>i</sub> < right<sub>i</sub> <= 1000</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • findLongestChain

      public int findLongestChain(int[][] pairs)