Maximum Length of Pair Chain【双链的最大长度】

来源:互联网 发布:网络 第二办公室 编辑:程序博客网 时间:2024/06/18 04:55

一、题目

英文:Maximum Length of Pair Chain

中文:双链的最大长度

二、内容要求

英文:

You are given n pairs of numbers. In every pair, the first number is always smaller than the second number.

Now, we define a pair (c, d) can follow another pair (a, b) if and only if b < c. Chain of pairs can be formed in this fashion.

Given a set of pairs, find the length longest chain which can be formed. You needn't use up all the given pairs. You can select pairs in any order.

中文:给定一组数对,我们定义当且仅当b < c时,(c, d)可以链在(a, b)之后。求可以组成的最长数对链的长度。

三、示例

Input: [[1,2], [2,3], [3,4]]Output: 2Explanation: The longest chain is [1,2] -> [3,4]

四、代码


1.java代码

注:利用的lambda 表达式知识点,可看http://www.jianshu.com/p/85affe38ce5c
原创粉丝点击