当前位置:网站首页>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;
}
};
边栏推荐
- Photo scale correction tool: DxO viewpoint 3 direct mount version
- C陷阱与缺陷 第3章 语义“陷阱” 3.3 作为参数的数组声明
- [open the door to the new world] see how the old bird of testing plays API testing between applause
- Codeworks 5 questions per day (average 1500) - day 25
- July 28, 2022 Gu Yujia's study notes
- Algorithm --- paint the house (kotlin)
- 复现20字符短域名绕过以及xss相关知识点
- C陷阱与缺陷 第3章 语义“陷阱” 3.8 运算符&&、||和!
- Chapter 2 VRP command line
- Multi table (Association) query of SQL query data
猜你喜欢

Algorithm --- paint the house (kotlin)

Singleton mode (hungry and lazy)

A case of gradually analyzing the splitting of classes -- colorful ball collisions

STC MCU drive 1.8 'TFT SPI screen demonstration example (including data package)

The Federal Reserve raised interest rates again, Powell "let go of doves" at 75 basis points, and US stocks reveled

Let's talk about the summary of single merchant function modules

数字图像处理 第10章——图像分割

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

Apache文件管理自学笔记——映射文件夹和基于单ip多域名配置apache虚拟机

During the year, the first "three consecutive falls" of No. 95 gasoline returned to the "8 Yuan era"“
随机推荐
照片比例校正工具:DxO ViewPoint 3 直装版
国产ERP有没有机会击败SAP ?
Flask creation process day05-06 creation project
Redis配置缓存过期监听事件触发
STC单片机驱动1.8‘TFT SPI屏幕演示示例(含资料包)
4000 多字学懂弄通 js 中 this 指向问题,顺便手写实现 call、apply 和 bind
Alibaba Sentinel - workflow and principle analysis
军品技术文件划分及说明
年内首个“三连跌” 95号汽油回归“8元时代“
Three military product baselines (functional baseline, distribution baseline, product baseline) and the documents contained in the baseline
C traps and defects Chapter 3 semantic "traps" 3.9 integer overflow
C陷阱与缺陷 第3章 语义“陷阱” 3.4 避免“举偶法”
Introduction and advanced MySQL (13)
C and pointer Chapter 3 semantic "trap" 3.5 null pointer is not a string
Redis configuration cache expiration listening event trigger
CUDA GDB prompt: /tmp/tmpxft**** cudafe1.stub. c: No such file or directory.
Division and description of military technical documents
C traps and defects Chapter 3 semantic "traps" 3.3 array declaration as parameters
"PHP Basics" output approximate value of PI
Server operation management system