Java | Leetcode Java题解之第406题根据身高重建队列

题目:

题解:

java 复制代码
class Solution {
    public int[][] reconstructQueue(int[][] people) {
        Arrays.sort(people, new Comparator<int[]>() {
            public int compare(int[] person1, int[] person2) {
                if (person1[0] != person2[0]) {
                    return person2[0] - person1[0];
                } else {
                    return person1[1] - person2[1];
                }
            }
        });
        List<int[]> ans = new ArrayList<int[]>();
        for (int[] person : people) {
            ans.add(person[1], person);
        }
        return ans.toArray(new int[ans.size()][]);
    }
}
相关推荐
Adios7944 小时前
设置交集大小至少为2
数据结构·算法·leetcode
Jelena157795857927 小时前
电商运营分析数据比价接口实战:多平台价格监控与智能决策系统
java·大数据·数据库
神明不懂浪漫8 小时前
【第五章】Java中的继承与多态
java·开发语言
AI多Agent协作实战派10 小时前
AI多Agent协作系统实战(十七):凌晨4点,我的AI系统在“假装工作“——3个bug同时爆炸的5小时
java·前端·bug
gaolei_eit10 小时前
Java+Ai+vue
java·spring·maven
qq_25183645710 小时前
基于java Web 动漫视频网站毕业论文
java·开发语言·前端
LayZhangStrive10 小时前
JUC相关的函数、注解、变量杂记
java·面试·多线程·juc
未秃头的程序猿10 小时前
给公司做了个AI客服Agent,用的Spring AI 1.0,3天上线领导拍板了
java·后端·ai编程
曹牧10 小时前
Eclipse 批量文本替换
java·ide·eclipse
程序员清风10 小时前
OpenAI官方发布最新提示词技巧!
java·后端·面试