1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
maximum-length-of-pair-chain.cpp 504 Bytes
Copy Edit Raw Blame History
Allen Liu authored 8 years ago . add
// Time: O(nlogn)
// Space: O(1)
class Solution {
public:
int findLongestChain(vector<vector<int>>& pairs) {
sort(pairs.begin(), pairs.end(),
[](const vector<int>& a, const vector<int>& b) {
return a[1] < b[1];
});
int cnt = 0;
for (int i = 0, j = 0; j < pairs.size(); ++j) {
if (j == 0 || pairs[i][1] < pairs[j][0]) {
++cnt;
i = j;
}
}
return cnt;
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

Search