记载下这个题中的语法(对这些语法的使用不熟悉)
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                记载下这个题中的语法(对这些语法的使用不熟悉)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                ?這個題的解法按照身高h降序和k升序對數組中的元素進行排列,然后插入的時候按照索引進行插入
class Solution { public:vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {//身高降序排列,人數升序排列 //自定義排序方式,因為是vector<vector<int>>類型的,所以需要自己定義sort的比較函數。a[0]代表第一//people[i]的第一個元素。sort(people.begin(), people.end(), [](const vector<int>& a, const vector<int>& b){if(a[0] > b[0]) return true;if(a[0] == b[0] && a[1] <b[1])return true;return false;});vector<vector<int>> res;for(int i = 0; i < people.size(); i++){res.insert(res.begin() + people[i][1], people[i]);//resert函數在res.begin() + //people[i][1],位置之前插入people[i].}/*for(auto& e : people){res.insert(res.begin() + e[1], e);}*/return res;} };?
總結
以上是生活随笔為你收集整理的记载下这个题中的语法(对这些语法的使用不熟悉)的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 一道题教会你回溯、动态规划、贪心
- 下一篇: 车机app
