-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2418.按身高排序.cpp
executable file
·50 lines (43 loc) · 1016 Bytes
/
2418.按身高排序.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* @lc app=leetcode.cn id=2418 lang=cpp
* @lcpr version=21907
*
* [2418] 按身高排序
*/
using namespace std;
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
// @lc code=start
class Solution {
public:
vector<string> sortPeople(vector<string>& names, vector<int>& heights) {
vector<string> ans;
vector<int> indexes;
for(int i=0;i<names.size();i++)indexes.push_back(i);
sort(indexes.begin(),indexes.end(),[&](int a,int b)->bool{return heights[a]>heights[b];});
for(int i:indexes)ans.push_back(names[i]);
return ans;
}
};
// @lc code=end
/*
// @lcpr case=start
// ["Mary","John","Emma"]\n[180,165,170]\n
// @lcpr case=end
// @lcpr case=start
// ["Alice","Bob","Bob"]\n[155,185,150]\n
// @lcpr case=end
*/