class Solution {
public int[][] reconstructQueue(int[][] people) {
//根据身高排序
Arrays.sort(people,(a,b) ->{
if(a[0] == b[0]) return a[1] - b[1];
return b[0] - a[0];//b - a 是降序排列
});
LinkedList<int[]> que = new LinkedList<>();
//插入
for(int[] p :people){
que.add(p[1],p);
}
return que.toArray(new int[people.length][]);
}
}
class Solution {
public int findMinArrowShots(int[][] points) {
int count = 1;
Arrays.sort(points, (a,b) -> Integer.compare(a[0],b[0]));
for(int i = 1; i< points.length; i++){
if(points[i-1][1] >= points[i][0]){
//同时射 更新重叠气球范围
points[i][1] = Math.min(points[i][1],points[i-1][1]);
}else if(points[i-1][1] < points[i][0]){
count++;
}
}
return count;
}
}
class Solution {
public int eraseOverlapIntervals(int[][] intervals) {
int count = 0;
Arrays.sort(intervals,(a,b) -> Integer.compare(a[0] , b[0]));
for(int i = 1; i<intervals.length;i++){
if(intervals[i-1][1] > intervals[i][0]){
count++;
intervals[i][1] = Math.min(intervals[i-1][1],intervals[i][1]);
}
}
return count;
}
}
class Solution {
public List<Integer> partitionLabels(String s) {
//用hash记录最远距离
List<Integer> list = new LinkedList<>();
int[] edge = new int[26];
char[] ch = s.toCharArray();
for(int i = 0 ; i<ch.length ; i++){
edge[ch[i] - 'a'] = i;
}
int index = 0;
int last = -1;
for(int i = 0 ; i < ch.length; i++){
//更新最远
index = Math.max(edge[ch[i] - 'a'] , index);
if(i == index){
list.add(i - last);
last = i;
}
}
return list;
}
}