leetcode 406. 根据身高重建队列

image

将数组排序:按照h降序,h相同的按照k升序。然后,遍历,并按照k,进行下标插入。

class Solution {
    public int[][] reconstructQueue(int[][] people) {
        Arrays.sort(people,(a,b)->{
            if(a[0]!=b[0]) return b[0]-a[0];
            else return a[1]-b[1];
        });
        List<int[]> list=new LinkedList<>();
        for(int[] p:people){
            list.add(p[1],p);
        }
        return list.toArray(new int[list.size()][]);
    }
}
posted @ 2022-02-21 20:02  livingsu  阅读(20)  评论(0)    收藏  举报