We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 274a01e commit a33a2bfCopy full SHA for a33a2bf
src/main/java/com/fishercoder/solutions/_646.java
@@ -26,4 +26,26 @@ public int findLongestChain(int[][] pairs) {
26
}
27
28
29
+ public static class Solution2 {
30
+ /**
31
+ * credit: https://leetcode.com/problems/maximum-length-of-pair-chain/discuss/105623/Java-Very-Simple-without-DP
32
+ */
33
+ public int findLongestChain(int[][] pairs) {
34
+ Arrays.sort(pairs, (a, b) -> a[0] - b[0]);
35
+ int len = 0;
36
+ int pre = Integer.MIN_VALUE;
37
+ for (int[] pair : pairs) {
38
+ if (pair[0] > pre) {
39
+ //not overlap
40
+ len++;
41
+ pre = pair[1];
42
+ } else if (pair[1] < pre) {
43
+ //overlap but with a smaller second number
44
45
+ }
46
47
+ return len;
48
49
50
+
51
0 commit comments