当前位置:网站首页>leetcode 406. Queue Reconstruction by Height 根据身高重建队列(中等)
leetcode 406. Queue Reconstruction by Height 根据身高重建队列(中等)
2022-07-30 22:56:00 【InfoQ】
一、题目大意
- 1 <= people.length <= 2000
- 0 <= hi <= 106
- 0 <= ki < people.length
- 题目数据确保队列可以被重建
二、解题思路
三、解题方法
3.1 Java实现
public class Solution {
public int[][] reconstructQueue(int[][] people) {
// 先对people按身高进行排序
Arrays.sort(people, (a, b) -> a[0] == b[0] ? a[1] - b[1] : b[0] - a[0]);
for (int i = 1; i < people.length; i++) {
int cnt = 0;
for (int j = 0; j < i; j++) {
if (cnt == people[i][1]) {
int[] t = people[i];
for (int k = i - 1; k >= j; k--) {
people[k+1] = people[k];
}
people[j] = t;
break;
}
cnt++;
}
}
return people;
}
}
四、总结小记
- 2022/7/30 7月倒数第二天,最近两天有大雨
边栏推荐
- Debezium报错系列之二十:task failed to create new topic.Ensure that the task is authorized to create topics
- HF2022-EzPHP复现
- ZZULIOJ: 1120: the most value to exchange
- 482-静态库、动态库的制作、使用及区别
- OpenCV笔记(二十):滤波函数——filter2D
- ZZULIOJ:1119: 数列有序
- 【LeetCode】64. 最小路径和 - Go 语言题解
- WSL2设置默认启动用户(debian)
- 【LeetCode】42. 接雨水 - Go 语言题解
- MySql统计函数COUNT详解
猜你喜欢
Ningbo Zhongning Pawn will transfer 29.5% of the equity for 2.8338 million yuan, and the owner's equity in 2021 will be 9.6875 million yuan
只会纯硬件,让我有点慌
【微信小程序】小程序突破小程序二维码数量限制
IJCAI2022教程 | 口语语言理解:最新进展和新领域
WSL安装图形界面并通过xrdp/X-Launch访问
2021GDCPC广东省大学生程序设计竞赛 H.History
电脑快捷方式图标变白解决方案
EasyExcel综合课程实战
EasyExcel comprehensive course combat
网安学习-内网渗透3
随机推荐
【LeetCode】64. 最小路径和 - Go 语言题解
MySQL进阶sql性能分析
宁波中宁典当转让29.5%股权为283.38万元,2021年所有者权益为968.75万元
【Untitled】
Gxlcms有声小说系统/小说听书系统源码
for...in 和 for...of 的区别
阿里云视频点播+项目实战
Apache Doris系列之:安装与部署详细步骤
Computer shortcut icon whitening solution
Successfully solved ImportError: always import the name '_validate_lengths'
el-upload添加请求头
A detailed explanation: SRv6 Policy model, calculation and drainage
#yyds干货盘点# 面试必刷TOP101:判断链表中是否有环
【LeetCode】55. 跳跃游戏 - Go 语言题解
Learning about XML (1)
一文详解:SRv6 Policy模型、算路及引流
ThinkPHP高仿蓝奏云网盘系统源码/对接易支付系统程序
二进制序列
mysql锁机制
The problem of sticky packets in tcp protocol transmission