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

边栏推荐
- Market status and development prospect prediction of global neutral silicone sealant industry in 2022
- Current market situation and development prospect forecast of global UV sensitive resin 3D printer industry in 2022
- Concurrent operation memory interaction
- Silent authorization login and registration of wechat applet
- 2022-02-12 daily clock in: problem fine brush
- Wechat applet waterfall flow and pull up to the bottom
- Notes | numpy-10 Iterative array
- 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
- [research materials] the fourth quarter report of the survey of Chinese small and micro entrepreneurs in 2021 - Download attached
- 关于开学的准备与专业认知
猜你喜欢

Analysis of proxy usage of ES6 new feature
![[research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached](/img/95/833f5ec20207ee5d7e6cdfa7208c5e.jpg)
[research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached

逆袭大学生的职业规划
![[XSS bypass - protection strategy] understand the protection strategy and better bypass](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[XSS bypass - protection strategy] understand the protection strategy and better bypass

The usage of micro service project swagger aggregation document shows all micro service addresses in the form of swagger grouping

Unity tool Luban learning notes 1

论文阅读_清华ERNIE

Review the configuration of vscode to develop golang

MC Layer Target

Oracle SQL table data loss
随机推荐
Compile and decompile GCC common instructions
Symbol of array element product of leetcode simple problem
SSM framework integration
UiPath实战(08) - 选取器(Selector)
Thesis reading_ ICD code_ MSMN
Keepalived热备与HAProxy
Huawei personally ended up developing 5g RF chips, breaking the monopoly of Japan and the United States
论文阅读_ICD编码_MSMN
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
Mobile terminal - uniapp development record (public request encapsulation)
Shell script Basics - basic grammar knowledge
Market status and development prospect prediction of the near infrared sensor industry of the global Internet of things in 2022
1103 integer factorization (30 points)
1086 tree traversals again (25 points)
文献阅读_基于多模态数据语义融合的旅游在线评论有用性识别研究(中文文献)
Preparation for school and professional cognition
[set theory] relational representation (relational matrix | examples of relational matrix | properties of relational matrix | operations of relational matrix | relational graph | examples of relationa
[XSS bypass - protection strategy] understand the protection strategy and better bypass
[set theory] relationship properties (symmetry | symmetry examples | symmetry related theorems | antisymmetry | antisymmetry examples | antisymmetry theorems)
Handling record of electric skateboard detained by traffic police