当前位置:网站首页>leetcode406. Rebuild the queue based on height
leetcode406. Rebuild the queue based on height
2022-07-03 04:58:00 【Day by day, the dish chicken Jie!!】
One : You don't have to turn against the wind , But please be born to the sun

Two : subject

3、 ... and : Upper code
class Solution {
public:
/** Analyze the meaning of the topic : This gives people In the array , We need according to its elements people[i] = [hi,ki]; And then according to its ki To indicate greater than hi The number of tall people , To sort . Ideas :1. First we have to sort , So which key value do we sort by ? 1>: If the k Value sorting , It won't work people = [[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]] If the k If it's worth it Then [4,4] will At the end , It violates its front only 4 A rule that height is higher than height 2>: Then press h sorted From high to low If we meet people of similar height, we need to k It's worth putting the small one in front ( because k It means before The height of the face is higher ), When the order is arranged in this way, the rest is to insert . After arranging the order : [[7,0],[7,1],[6,1],[5,0],[5,2],[4,4]] We take [5,2] give an example ,[5,2] The front one must be better than 5 higher , Then we can insert it in the subscript 2 The location of , Because the front Subscript to be 0,1 Is taller than his height */
static bool cmp(const vector<int> &v1,const vector<int> &v2) {
if(v1[0] == v2[0]) return v1[1] < v2[1];// When the body height is the same , Let's compare k value
return v1[0] > v2[0];
}
vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {
sort(people.begin(),people.end(),cmp);
vector<vector<int> >ans;
for(int i = 0; i < people.size(); i++) {
int postion = people[i][1];// Get the subscript to insert
ans.insert(ans.begin()+postion,people[i]);
}
return ans;
}
};

边栏推荐
- Messy change of mouse style in win system
- Thesis reading_ ICD code_ MSMN
- ZABBIX monitoring of lamp architecture (2): ZABBIX basic operation
- MediaTek 2023 IC written examination approved in advance (topic)
- Concurrent operation memory interaction
- "Niuke brush Verilog" part II Verilog advanced challenge
- 《牛客刷verilog》Part II Verilog进阶挑战
- 普通本科大学生活避坑指南
- The consumption of Internet of things users is only 76 cents, and the price has become the biggest obstacle to the promotion of 5g industrial interconnection
- Market status and development prospect prediction of global fermented plant protein industry in 2022
猜你喜欢

Prepare for 2022 and welcome the "golden three silver four". The "summary of Android intermediate and advanced interview questions in 2022" is fresh, so that your big factory interview can go smoothly

Handling record of electric skateboard detained by traffic police

【批处理DOS-CMD命令-汇总和小结】-CMD窗口的设置与操作命令-关闭cmd窗口、退出cmd环境(exit、exit /b、goto :eof)

Online VR model display - 3D visual display solution

【工具跑SQL盲注】

Actual combat 8051 drives 8-bit nixie tube

逆袭大学生的职业规划
![[tools run SQL blind note]](/img/c3/86db4568b221d2423914990a88eec2.png)
[tools run SQL blind note]

Introduction to JVM principle

Compile and decompile GCC common instructions
随机推荐
Problems encountered in fuzzy query of SQL statements
Review the configuration of vscode to develop golang
[research materials] 2022q1 game preferred casual game distribution circular - Download attached
Literature reading_ Research on the usefulness identification of tourism online comments based on semantic fusion of multimodal data (Chinese Literature)
Market status and development prospect prediction of the global fire hose industry in 2022
并发操作-内存交互操作
论文阅读_清华ERNIE
MySQL winter vacation self-study 2022 12 (3)
Mobile terminal - uniapp development record (public request encapsulation)
最大连续子段和(动态规划,递归,递推)
1094 the largest generation (25 points)
[research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached
Sprintf formatter abnormal exit problem
1114 family property (25 points)
Realize file download through the tag of < a > and customize the file name
Thesis reading_ Chinese medical model_ eHealth
@RequestMapping
50 practical applications of R language (36) - data visualization from basic to advanced
The current market situation and development prospect of the global gluten tolerance test kit industry in 2022
Retirement plan fails, 64 year old programmer starts work again