Created
August 15, 2020 21:30
-
-
Save IngeFrodo/c57c5ebfa84783c2b8db89945c5ed49a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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