当前位置:网站首页>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;
}
};

边栏推荐
- M1 Pro install redis
- Learn to use the idea breakpoint debugging tool
- Shell script -- condition judgment
- Retirement plan fails, 64 year old programmer starts work again
- Market status and development prospect prediction of the global fire hose industry in 2022
- 【XSS绕过-防护策略】理解防护策略,更好的绕过
- Market status and development prospect prediction of global fermented plant protein industry in 2022
- What is UUID
- Online VR model display - 3D visual display solution
- Market status and development prospect prediction of the global forward fluorescent microscope industry in 2022
猜你喜欢

《牛客刷verilog》Part II Verilog进阶挑战

5-36v input automatic voltage rise and fall PD fast charging scheme drawing 30W low-cost chip

Handler understands the record

MediaTek 2023 IC written examination approved in advance (topic)

Cross platform plug-in flutter for displaying local notifications_ local_ notifications
![[research materials] annual report of China's pension market in 2021 - Download attached](/img/24/622aeeb38de16ac84128b362ceeddb.jpg)
[research materials] annual report of China's pension market in 2021 - Download attached

关于开学的准备与专业认知

First + only! Alibaba cloud's real-time computing version of Flink passed the stability test of big data products of the Institute of ICT
![[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree](/img/0f/bc8c44aee7a2c9dccac050b1060017.jpg)
[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree

论文阅读_清华ERNIE
随机推荐
Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis
Realize file download through the tag of < a > and customize the file name
普通本科大学生活避坑指南
Market status and development prospects of the global automatic tea picker industry in 2022
Handling record of electric skateboard detained by traffic police
"Niuke brush Verilog" part II Verilog advanced challenge
[set theory] relation properties (reflexivity | reflexivity theorem | reflexivity | reflexivity theorem | example)
Without 50W bride price, my girlfriend was forcibly dragged away. What should I do
Thesis reading_ Chinese NLP_ ELECTRA
Network security textual research recommendation
The 19th Zhejiang I. barbecue
Sprintf formatter abnormal exit problem
Market status and development prospect prediction of the global fire alarm sensor industry in 2022
STM32 reverse entry
Objects. Requirenonnull method description
2022-02-11 daily clock in: problem fine brush
The process of browser accessing the website
Learn to use the idea breakpoint debugging tool
sql语句模糊查询遇到的问题
文献阅读_基于多模态数据语义融合的旅游在线评论有用性识别研究(中文文献)