Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions dlek-user/[646] Maximum Length of Pair Chain
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
public int findLongestChain(int[][] pairs) {
Arrays.sort(pairs, (a, b) -> a[1] - b[1]);

int count = 0;
int currentEnd = Integer.MIN_VALUE;

for (int[] pair : pairs) {

if (pair[0] > currentEnd) {
count++;
currentEnd = pair[1];
}
}

return count;
}
}