当前位置:网站首页>406.根据身高重建队列
406.根据身高重建队列
2022-07-30 05:38:00 【Linke66】

思路:
按身高降序排列,假如身高一样就按升序排列。
接下来,创建一个数组ret保存结果,遍历people数组;people第二个元素的值就是该people要插入数组ret中的位置,因为身高是按降序排列,而身高相同则按k升序排列,因此一定不会影响到后面的元素,如下图所示。
class Solution {
public:
vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {
sort(people.begin(),people.end(),[](const vector<int>& v1,const vector<int>& v2)
{
//h按降序排序,假如h相等k按升序排序
return v1[0]>v2[0]||(v1[0]==v2[0]&&v1[1]<v2[1]);
});
vector<vector<int>> ret;
for(auto p:people)
{
ret.insert(ret.begin()+p[1],p);
}
return ret;
}
};
边栏推荐
- Graphic mirror symmetry (schematic diagram)
- 质数(清华大学机试题)(DAY 86)
- numpy中np.inf函数的用法讲解
- [Mysql] CONVERT function
- [Koltin Flow (1)] Five ways to create flow
- 4、nerf(pytorch)
- create-nuxt-app创建出来的项目没有server
- Different lower_case_table_names settings for server (‘1‘) and data dictionary (‘0‘) 解决方案
- 每日练习------输出一个整数的二进制数、八进制数、十六进制数。
- MySQL 灵魂 16 问,你能撑到第几问?
猜你喜欢
随机推荐
cnpm安装步骤
MYSQL-InnoDB的线程模型
Oracle补丁体系及Opatch工具介绍
cmd (command line) to operate or connect to the mysql database, and to create databases and tables
nacos-2.0.3启动报错出现no datasource set的坑
MySQL-Explain详解
Introduction to Oracle Patch System and Opatch Tool
“tensorflow.keras.preprocessing“ has no attribute “image_dataset_from_directory“
G Bus Count (Google Kickstart2014 Round D Problem B) (DAY 89)
2022年比若依更香的开源项目
optimizer.zero_grad()
坠落的蚂蚁(北京大学考研机试题)
SRA数据下载方法总结
list(列表)和array(数组)的区别
[Mysql] DATEDIFF function
Learn FPGA from the underlying structure (6) ---- Distributed RAM (DRAM, Distributed RAM)
[GO语言基础] 一.为什么我要学习Golang以及GO语言入门普及
It is enough for MySQL to have this article (37k words, just like Bojun!!!)
enumerate() 函数
Difference between cookie and session









