当前位置:网站首页>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;
}
};
边栏推荐
- SAP 中国本地化内容汇总
- mycat读写分离配置
- Chapter 2 VRP command line
- Sanzi chess (player + computer)
- Server operation management system
- Calculation of array serial number of force deduction questions (daily question 7/28)
- Practical guidance for interface automation testing (Part I): what preparations should be made for interface automation
- Incremental real-time disaster recovery notes
- "PHP Basics" output approximate value of PI
- C陷阱与缺陷 第3章 语义“陷阱” 3.9 整数溢出
猜你喜欢

Digital image processing Chapter 10 - image segmentation

【C】数组

How to solve the time zone problem in MySQL timestamp

Navicat new database

2022-07-28 第四小组 修身课 学习笔记(every day)

Flask的创建的流程day05-06之创建项目
![LeetCode 1331 数组序号转换[Map] HERODING的LeetCode之路](/img/be/d429d0c437dc5ed7cb4448e223a83a.png)
LeetCode 1331 数组序号转换[Map] HERODING的LeetCode之路

04 | background login: login method based on account and password (Part 1)

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

单例模式(饿汉式 懒汉式)
随机推荐
Codeworks 5 questions per day (average 1500) - day 25
C obtains JSON format data asynchronously from the web address
逐步分析类的拆分之案例——五彩斑斓的小球碰撞
Tp5.0 applet users do not need to log in and directly obtain the user's mobile number.
数字图像处理 第10章——图像分割
C traps and defects Chapter 3 semantic "traps" 3.3 array declaration as parameters
C language programming | exchange binary odd and even bits (macro Implementation)
During the year, the first "three consecutive falls" of No. 95 gasoline returned to the "8 Yuan era"“
MYCAT read / write separation configuration
How to deploy sentinel cluster of redis
反脆弱·从不确定性中获益---管理?
01-sdram: Code of initialization module
【机器人学习】机械臂抓手matlab运动学与admas动力学分析
C陷阱与缺陷 第3章 语义“陷阱” 3.4 避免“举偶法”
The Federal Reserve raised interest rates again, Powell "let go of doves" at 75 basis points, and US stocks reveled
C陷阱与缺陷 第3章 语义“陷阱” 3.3 作为参数的数组声明
军品研制过程-转阶段
Hangao database best practice configuration tool Hg_ BP log collection content
力扣刷题之分数加减运算(每日一题7/27)
[NPM error] - NPM err code eresolve and NPM err eresolve could not resolve problems