-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSolution646.java
More file actions
33 lines (31 loc) · 929 Bytes
/
Solution646.java
File metadata and controls
33 lines (31 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.Arrays;
/**
* Created by slade on 2019/12/19.
*/
class Solution646 {
public int findLongestChain(int[][] pairs) {
Arrays.sort(pairs, (a, b) -> {
if (a[1] != b[1]) {
return a[1] - b[1];
} else {
return a[0] - b[0];
}
});
int start = Integer.MIN_VALUE;
int ans = 0;
for (int[] item : pairs
) {
System.out.println(Arrays.toString(item));
if (item[0] > start) {
ans += 1;
start = item[1];
}
}
return ans;
}
public static void main(String[] args) {
Solution646 solution646 = new Solution646();
int[][] pairs = new int[][]{{-6, 9}, {1, 6}, {8, 10}, {-1, 4}, {-1, 4}, {-6, -2}, {-9, 8}, {-5, 3}, {-0, 3}};
System.out.println(solution646.findLongestChain(pairs));
}
}