当前位置:网站首页>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月倒数第二天,最近两天有大雨
边栏推荐
- 2022 Nioke Summer Multi-School Training Camp 1 J Serval and Essay
- MySQL联合查询(多表查询)
- Navicat cannot connect to mysql super detailed processing method
- Go语学习笔记 - gorm使用 - gorm处理错误 Web框架Gin(十)
- “蔚来杯“2022牛客暑期多校训练营4 DHKLN
- 通过社交媒体建立个人IP的 5 种行之有效的策略
- 反转链表-头插反转法
- el-upload添加请求头
- When Navicat connects to MySQL, it pops up: 1045: Access denied for user 'root'@'localhost'
- Learning about XML (1)
猜你喜欢
电脑快捷方式图标变白解决方案
IDEA使用技巧
# # yyds dry goods inventory interview will brush TOP101: to determine whether there is a part of the list
Apache Doris series: In-depth understanding of real-time analytical database Apache Doris
2sk2225代换3A/1500V中文资料【PDF数据手册】
【云驻共创】HCSD大咖直播–就业指南
win10重建索引
关于XML的学习(一)
Abstract classes and interfaces (study notes)
Computer shortcut icon whitening solution
随机推荐
vscode上利用screen命令跑代码
proemthues 服务发现配置
grub learning
Debezium报错系列之二十:task failed to create new topic.Ensure that the task is authorized to create topics
宁波中宁典当转让29.5%股权为283.38万元,2021年所有者权益为968.75万元
【无标题】
Mysql进阶优化篇01——四万字详解数据库性能分析工具(深入、全面、详细,收藏备用)
通过社交媒体建立个人IP的 5 种行之有效的策略
“蔚来杯“2022牛客暑期多校训练营4 N.Particle Arts 规律 方差
Golang go-redis cluster模式下不断创建新连接,效率下降问题解决
二进制序列
【Untitled】
PyTorch模型导出到ONNX文件示例(LeNet-5)
mysql获取当前时间
Learning about XML (1)
第十九周进度(了解物联网基础知识)
Compressing Deep Graph Neural Networks via Adversarial Knowledge Distillation
Py之pdpbox:pdpbox的简介、安装、案例应用之详细攻略
language code table
Apache Doris series: detailed steps for installation and deployment