当前位置:网站首页>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;
}
};
边栏推荐
- cross_val_score的用法
- St. Regis Takeaway Project: New dishes and dishes paged query
- [Image processing] Image skeleton extraction based on central axis transformation with matlab code
- asyncawait和promise的区别
- Teach you to completely uninstall MySQL
- Memories · The last system design in the university era
- Ranking of grades (Huazhong University of Science and Technology postgraduate examination questions) (DAY 87)
- 2022 Pengcheng Cup web
- 微积分 / 自动求导
- argparse —— 命令行选项、参数和子命令解析器
猜你喜欢
随机推荐
MySql fuzzy query Daquan
This dependency was not found:
MySQL user authorization
Solve the problem that the local nacos is not configured but the localhost8848 connection exception always occurs
[Image detection] Research on cumulative weighted edge detection method based on grayscale image with matlab code
Introduction to Oracle Patch System and Opatch Tool
Mysql8.+学习笔记
4、nerf(pytorch)
HCIP-第九天-BGP(边界网关协议)
MySQL-Explain详解
cross_val_score的用法
Summary of SQL classic interview questions in 2022 (with analysis)
Basic syntax of MySQL DDL and DML and DQL
Different lower_case_table_names settings for server ('1') and data dictionary ('0') solution
[Koltin Flow (1)] Five ways to create flow
Ranking of grades (Huazhong University of Science and Technology postgraduate examination questions) (DAY 87)
成绩排序(华中科技大学考研机试题)(DAY 87)
每日练习------输出一个整数的二进制数、八进制数、十六进制数。
数据操作 / 数据预处理
create-nuxt-app创建出来的项目没有server
![[Mysql] DATEDIFF function](/img/cd/7d19e668701cdd5542b6e43f4c2ad4.png)








