Skip to content

Instantly share code, notes, and snippets.

@IngeFrodo
Created August 15, 2020 21:30
Show Gist options
  • Save IngeFrodo/c57c5ebfa84783c2b8db89945c5ed49a to your computer and use it in GitHub Desktop.
Save IngeFrodo/c57c5ebfa84783c2b8db89945c5ed49a to your computer and use it in GitHub Desktop.
class NonOverlappingIntervals {
public int eraseOverlapIntervals(int[][] intervals) {
Arrays.sort(intervals, (a, b) -> a[1] - b[1]);
int erase = 0;
int end = Integer.MIN_VALUE;
for (int[] interval : intervals) {
if (end > interval[0]) {
erase++;
} else {
end = interval[1];
}
}
return erase;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment