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()][]);
    }
}
相关推荐
zander25816 分钟前
35. 搜索插入位置:从边界语义理解二分查找
数据结构·算法·leetcode
骇客野人16 分钟前
IntelliJ IDEA 菜单中英对照
java·ide·intellij-idea
我命由我1234517 分钟前
Kotlin 面向对象 - 枚举排序
android·java·开发语言·java-ee·kotlin·android studio·android-studio
Sam_Deep_Thinking37 分钟前
用Java 17从0到1写一个mini版RPC,理解远程调用的本质
java·面试·rpc·程序员·系统架构
yyds_yyd_100861 小时前
3731. 找出缺失的元素(2026.08.04)
c++·leetcode
敲代码的嘎仔1 小时前
从零搭建微服务:Spring Cloud Alibaba 全家桶踩坑实录(Nacos + OpenFeign + Gateway + Sentinel)
java·spring boot·spring·spring cloud·微服务·gateway·sentinel
一条泥憨鱼2 小时前
苍穹外卖【day7| 对购物车进行操作】
java·后端·mysql·苍穹外卖
lueluelue4710 小时前
LeetCode:链表
算法·leetcode·链表
橘子汽水16813 小时前
Leetcode 23,543合并K个升序链表,二叉树的直径
算法·leetcode·链表
都叫我大帅哥13 小时前
Java JJWT 完全指南:从入门到生产级实践
java