当前位置:网站首页>Leetcode 1331 array sequence number conversion [map] the leetcode path of heroding
Leetcode 1331 array sequence number conversion [map] the leetcode path of heroding
2022-07-29 03:19:00 【HERODING23】

Their thinking :
Sort the array , Map with a hash table to get the sequence number corresponding to each number , Then re traverse the array and replace the elements in the array , The code is as follows :
class Solution {
public:
vector<int> arrayRankTransform(vector<int>& arr) {
vector<int> temp = arr;
sort(temp.begin(), temp.end());
unordered_map<int, int> mp;
for(auto& t : temp) {
if(!mp.count(t)) {
mp[t] = mp.size() + 1;
}
}
for(int i = 0; i < arr.size(); i ++) {
arr[i] = mp[arr[i]];
}
return arr;
}
};
边栏推荐
- Redis configuration cache expiration listening event trigger
- Introduction and advanced MySQL (XIV)
- The Federal Reserve raised interest rates again, Powell "let go of doves" at 75 basis points, and US stocks reveled
- C traps and defects Chapter 3 semantic "traps" 3.1 pointers and arrays
- Photo scale correction tool: DxO viewpoint 3 direct mount version
- Summary of SAP localized content in China
- Unity game special effects
- [QNX hypervisor 2.2 user manual]9.11 RAM (under update)
- Wechat's crazy use of glide - life cycle learning
- Shell编程规范与变量
猜你喜欢

Verilog:阻塞赋值和非阻塞赋值

C语言基础知识点汇总

【打开新世界大门】看测试老鸟如何把API 测试玩弄在鼓掌之间

Watermelon book learning Chapter 6 -- SVM

微信为之疯狂的Glide使用——之生命周期学习

Singleton mode (hungry and lazy)

Unity 之游戏特效

How to solve the time zone problem in MySQL timestamp

3D advanced renderer: artlandis studio 2021.2 Chinese version

13_ UE4 advanced_ Montage animation realizes attack while walking
随机推荐
原理知识用得上
Alibaba Sentinel - 工作流程及原理解析
shell脚本总结
Sanzi chess (player + computer)
CUDA GDB prompt: /tmp/tmpxft**** cudafe1.stub. c: No such file or directory.
微信为之疯狂的Glide使用——之生命周期学习
Introduction and advanced MySQL (XIV)
[NPM error] - NPM err code eresolve and NPM err eresolve could not resolve problems
SAP 中国本地化内容汇总
Reproduce 20 character short domain name bypass and XSS related knowledge points
"PHP Basics" output approximate value of PI
Redis之sentinel哨兵集群怎么部署
Introduction and advanced level of MySQL (12)
C traps and defects Chapter 3 semantic "traps" 3.9 integer overflow
【C】 Array
军品三大基线(功能基线、分配基线、产品基线)及基线包含的文件
Does domestic ERP have a chance to beat sap?
数字图像处理 第10章——图像分割
Server operation management system
C traps and defects Chapter 3 semantic "traps" 3.6 Boundary Calculation and asymmetric boundary