当前位置:网站首页>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月倒数第二天,最近两天有大雨
边栏推荐
- 【MySQL】MySQL中对数据库及表的相关操作
- CPM:A large-scale generative chinese pre-trained lanuage model
- Py's pdpbox: a detailed introduction to pdpbox, installation, and case application
- 一文详解:SRv6 Policy模型、算路及引流
- 成功解决ImportError: cannot import name ‘_validate_lengths‘
- QT 在父类中添加子类的流程,object tree,
- 2022 Nioke Summer Multi-School Training Camp 1 J Serval and Essay
- 网安学习-内网渗透3
- Golang 切片删除指定元素的几种方法
- EasyExcel综合课程实战
猜你喜欢

【LeetCode】55. 跳跃游戏 - Go 语言题解

VS2017 compile Tars test project
![[MySQL] Mysql transaction and authority management](/img/a5/c92e0404c6a970a62595bc7a3b68cd.gif)
[MySQL] Mysql transaction and authority management

微软商店出现【0x800706D9】解决方法

vscode上利用screen命令跑代码

Rust编译报错:error: linker `cc` not found

宁波中宁典当转让29.5%股权为283.38万元,2021年所有者权益为968.75万元

PyTorch model export to ONNX file example (LeNet-5)

Go1.18升级功能 - 泛型 从零开始Go语言

#Dasctf July Enabler WP
随机推荐
HF2022-EzPHP复现
WSL2设置默认启动用户(debian)
关于XML的学习(一)
Reverse linked list - head insertion inversion method
Py之pdpbox:pdpbox的简介、安装、案例应用之详细攻略
一文详解:SRv6 Policy模型、算路及引流
Debezium报错系列之二十:task failed to create new topic.Ensure that the task is authorized to create topics
$\text{ARC 145}$
d违反常了吗
QT 在父类中添加子类的流程,object tree,
阿里云视频点播+项目实战
PS Basic Learning (1)
2021GDCPC Guangdong University Student Programming Competition B.Byfibonacci
[SAM模板题] P3975 [TJOI2015] 弦论
IDEA使用技巧
# # yyds dry goods inventory interview will brush TOP101: to determine whether there is a part of the list
可视化工具Netron介绍
Alibaba Cloud video on demand + project combat
mysql锁机制
Go语学习笔记 - gorm使用 - 事务操作 Web框架Gin(十一)