class Solution {
public int eraseOverlapIntervals(int[][] intervals) {
Arrays.sort(intervals, new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
if (o1[0] == o2[0]) {
return Integer.compare(o1[1], o2[1]);
} else {
return Integer.compare(o1[0],o2[0]);
}
}
});
int res = 0;
int end = intervals[0][1];
for (int i = 1; i < intervals.length; i++) {
if(intervals[i][0]<end){
res++;
if(intervals[i][1] < end){
end = intervals[i][1];
}
}else {
end = intervals[i][1];
}
}
return res;
}
}
class Solution {
public List<Integer> partitionLabels(String s) {
List<Integer> list = new ArrayList<>();
HashMap<Character, Integer> map = new HashMap<>();
for (int i = 0; i < s.length(); i++) {
map.put(s.charAt(i), i);
}
int start = 0;
while (start < s.length()) {
int index = start;
int end = map.get(s.charAt(index));
while (index <= end) {
end = Math.max(map.get(s.charAt(index)), end);
index++;
}
list.add(end - start+1);
start = end+1;
}
return list;
}
}