20.11.14 leetcode1122(自定义排序)
2021-03-17 09:28
阅读:613
标签:end 定义排序 code problem else 暴力 https count rank
题目链接:https://leetcode-cn.com/problems/relative-sort-array/
又是一个简单题,懒得多说了,我用的暴力,有价值的地方就是题解用的这种自定义排序的方法, 之前没写过这样的自定义排序,码住。
class Solution { public: vectorint> relativeSortArray(vectorint>& arr1, vectorint>& arr2) { unordered_mapint, int> rank; for (int i = 0; i i) { rank[arr2[i]] = i; } sort(arr1.begin(), arr1.end(), [&](int x, int y) { if (rank.count(x)) { return rank.count(y) ? rank[x] true; } else { return rank.count(y) ? false : x y; } }); return arr1; } };
20.11.14 leetcode1122(自定义排序)
标签:end 定义排序 code problem else 暴力 https count rank
原文地址:https://www.cnblogs.com/qingjiuling/p/13973719.html
下一篇:排序算法之——选择排序
文章来自:搜素材网的编程语言模块,转载请注明文章出处。
文章标题:20.11.14 leetcode1122(自定义排序)
文章链接:http://soscw.com/index.php/essay/65252.html
文章标题:20.11.14 leetcode1122(自定义排序)
文章链接:http://soscw.com/index.php/essay/65252.html
评论
亲,登录后才可以留言!