编程练习(第八周)
2017-04-15 10:37
176 查看
406. Queue Reconstruction by Height
Add to ListDescriptionHintsSubmissionsSolutions
Total Accepted: 20635
Total Submissions: 37676
Difficulty: Medium
Contributor: LeetCode
Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers
(h, k), where
his the height of the person and
kis
the number of people in front of this person who have a height greater than or equal to
h.
Write an algorithm to reconstruct the queue.
题解:
bool comp(const pair<int, int>& p1, const pair<int, int>& p2){
return p1.first > p2.first || (p1.first == p2.first && p1.second < p2.second);
}
vector< pair<int, int> > reconstructQueue(vector< pair<int, int> >& people) {
sort(people.begin(), people.end(), comp);
vector< pair<int, int> > res;
for (int i=0; i<people.size(); i++)
res.insert(res.begin() + people[i].second, people[i]);
return res;
}
相关文章推荐
- 吴恩达Coursera深度学习(1-2)编程练习
- 字符串编程练习
- 《C++ GUI Qt4 编程(第二版)》2.4改变形状的对话框 练习源码
- python 核心编程课后练习(chapter 2)
- LeetCode编程练习 - Palindrome Linked List学习心得
- 强化练习2:编程实现统计某年某月份的天数
- LeetCode编程练习 - Power of Two学习心得
- 编程练习3——02
- 2017-2018-1 20155204 《信息安全系统设计基础》第八周课上实践、课下练习、学习总结
- 《Android权威编程指南(The Big Nerd Ranch Guide)(第二版)》12.4挑战练习
- Java基础编程小练习
- C语言常见的list一些编程练习
- python 核心编程课后练习(chapter 5)
- 编程练习——平衡树(AVLTree)
- LeetCode编程练习 - Reverse Vowels of a String学习心得
- unix 学习笔记-----Unix编程练习实例----读目录的实例_1
- 第四讲 类与对象 课堂编程练习1
- C Primer Plus 第七章 编程练习 1-6题
- C语言编程练习——最大的矩形
- C++ Primer Plus (第6版)编程练习 代码-----第八章