Skip to content

Commit 4f95c59

Browse files
authored
Update 646-maximum-length-of-pair-chain.js
1 parent 954c7ef commit 4f95c59

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

646-maximum-length-of-pair-chain.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
/**
2+
* @param {number[][]} pairs
3+
* @return {number}
4+
*/
5+
const findLongestChain = function(pairs) {
6+
let res = 0
7+
const n = pairs.length
8+
if(n === 0) return res
9+
pairs.sort((a, b) => a[1] - b[1])
10+
let end = pairs[0][1]
11+
res++
12+
for(let i = 1; i < n; i++) {
13+
const e = pairs[i]
14+
if(e[0] <= end) continue
15+
res++
16+
end = e[1]
17+
}
18+
19+
return res
20+
};
21+
22+
// another
23+
124
/**
225
* @param {number[][]} pairs
326
* @return {number}

0 commit comments

Comments
 (0)