- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSolution646.java
More file actions
Latest commit
33 lines (31 loc) · 929 Bytes
/
Copy pathSolution646.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
importjava.util.Arrays;
/**
* Created by slade on 2019/12/19.
*/
classSolution646 {
publicintfindLongestChain(int[][] pairs) {
Arrays.sort(pairs, (a, b) -> {
if (a[1] != b[1]) {
returna[1] - b[1];
} else {
returna[0] - b[0];
}
});
intstart = Integer.MIN_VALUE;
intans = 0;
for (int[] item : pairs
) {
System.out.println(Arrays.toString(item));
if (item[0] > start) {
ans += 1;
start = item[1];
}
}
returnans;
}
publicstaticvoidmain(String[] args) {
Solution646solution646 = newSolution646();
int[][] pairs = newint[][]{{-6, 9}, {1, 6}, {8, 10}, {-1, 4}, {-1, 4}, {-6, -2}, {-9, 8}, {-5, 3}, {-0, 3}};
System.out.println(solution646.findLongestChain(pairs));
}
}