当前位置:网站首页>LeetCode 1331 数组序号转换[Map] HERODING的LeetCode之路
LeetCode 1331 数组序号转换[Map] HERODING的LeetCode之路
2022-07-29 03:16:00 【HERODING23】

解题思路:
将数组进行排序,用哈希表进行映射得到每个数对应的序号,然后再重新遍历数组替换数组中的元素即可,代码如下:
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;
}
};
边栏推荐
- Sanzi chess (player + computer)
- C陷阱与缺陷 第3章 语义“陷阱” 3.7 求值顺序
- 12_ UE4 advanced_ Change a more beautiful character model
- C language small project - address book (static version + dynamic version + file version)
- 【FreeSwitch开发实践】media bug获取通话语音流
- MySQL忘记密码怎么办
- Flask的创建的流程day05-06之创建项目
- [freeswitch development practice] media bug obtains call voice flow
- Redis之sentinel哨兵集群怎么部署
- A case of gradually analyzing the splitting of classes -- colorful ball collisions
猜你喜欢

12_ue4进阶_换一个更好看的人物模型

Redis配置缓存过期监听事件触发

【C】 Array
![[freeswitch development practice] media bug obtains call voice flow](/img/14/9a359403606c312b30733d4a015fa5.png)
[freeswitch development practice] media bug obtains call voice flow

Unity 之游戏特效

During the year, the first "three consecutive falls" of No. 95 gasoline returned to the "8 Yuan era"“

mycat读写分离配置

逐步分析类的拆分之案例——五彩斑斓的小球碰撞

2. Nodejs -- path (\dirname, \filname), URL URL, querystring module, mime module, various paths (relative paths), web page loading (interview questions *)

Apache文件管理自学笔记——映射文件夹和基于单ip多域名配置apache虚拟机
随机推荐
Introduction and advanced level of MySQL (12)
GJB常见混淆概念
《QA离业务代码能有多近?》通过codediff直接暴露缺陷
Navicat new database
C traps and defects Chapter 3 semantic "traps" 3.8 operators &, |, and!
ShardingSphere之水平分表实战(三)
[freeswitch development practice] unimrcp compilation and installation
C traps and defects Chapter 3 semantic "traps" 3.4 avoid "couple method"
多行文本省略
13_ UE4 advanced_ Montage animation realizes attack while walking
服务器运行管理制度
Server operation management system
MYSQL入门与进阶(十三)
C陷阱与缺陷 第3章 语义“陷阱” 3.6 边界计算与不对称边界
The Federal Reserve raised interest rates again, Powell "let go of doves" at 75 basis points, and US stocks reveled
[open the door to the new world] see how the old bird of testing plays API testing between applause
MySQL large table joint query optimization, large transaction optimization, avoiding transaction timeout, lock wait timeout and lock table
融云 IM & RTC 能力上新盘点
Implement Lmax disruptor queue from scratch (VI) analysis of the principle of disruptor solving pseudo sharing and consumers' elegant stopping
Incremental real-time disaster recovery notes