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

边栏推荐
- Source insight garbled code solution
- Hire cashier (differential constraint)
- Current market situation and development prospect prediction of global direct energy deposition 3D printer industry in 2022
- Retirement plan fails, 64 year old programmer starts work again
- Current market situation and development prospect forecast of global UV sensitive resin 3D printer industry in 2022
- 最大连续子段和(动态规划,递归,递推)
- 1114 family property (25 points)
- Number of 1 in binary (simple difficulty)
- Blog building tool recommendation (text book delivery)
- Thesis reading_ ICD code_ MSMN
猜你喜欢

Use Sqlalchemy module to obtain the table name and field name of the existing table in the database

Sdl2 + OpenGL glsl practice (Continued)
![[research materials] 2022q1 game preferred casual game distribution circular - Download attached](/img/13/5a67c5d08131745759fdc70a71cf0f.jpg)
[research materials] 2022q1 game preferred casual game distribution circular - Download attached

联发科技2023届提前批IC笔试(题目)

Network security textual research recommendation

Online VR model display - 3D visual display solution
![[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

2022-02-11 daily clock in: problem fine brush

2022-02-12 daily clock in: problem fine brush

On typescript and grammar
随机推荐
Day 51 - tree problem
[set theory] relational representation (relational matrix | examples of relational matrix | properties of relational matrix | operations of relational matrix | relational graph | examples of relationa
Learn to use the idea breakpoint debugging tool
文献阅读_基于多模态数据语义融合的旅游在线评论有用性识别研究(中文文献)
Market status and development prospect prediction of the global fire hose industry in 2022
雇佣收银员(差分约束)
编译GCC遇到的“pthread.h” not found问题
Mobile terminal - uniapp development record (public request encapsulation)
《牛客刷verilog》Part II Verilog进阶挑战
The reason why the entity class in the database is changed into hump naming
Kept hot standby and haproxy
RT thread flow notes I startup, schedule, thread
The current market situation and development prospect of the global gluten tolerance test kit industry in 2022
sql语句模糊查询遇到的问题
1107 social clusters (30 points)
"Niuke brush Verilog" part II Verilog advanced challenge
移动端——uniapp开发记录(公共请求request封装)
联发科技2023届提前批IC笔试(题目)
Sprintf formatter abnormal exit problem
[research materials] 2022q1 game preferred casual game distribution circular - Download attached