当前位置:网站首页>6092. 替换数组中的元素
6092. 替换数组中的元素
2022-07-02 12:10:00 【紫菜(Nori)】
class Solution {
public:
vector<int> arrayChange(vector<int>& nums, vector<vector<int>>& operations) {
// 保存nums中所有元素的下标信息
// key: 值; value: 下标
map<int, int> map;
for(int i = 0; i < nums.size(); i++){
// 将值和对应的下标插入
map.emplace(nums[i], i);
}
// 遍历所有的操作
for(int i = 0; i < operations.size(); i++){
auto it = map.find(operations[i][0]);
// 由于一定存在,所以这里不用判断
// if(it == end(map)){
// continue;
// }
// 替换对应位置的值
int val = operations[i][1];
nums[it->second] = val;
// 更新或则插入新元素和对应的下标
map[val] = it->second;
}
return nums;
}
};边栏推荐
- FPGA - 7系列 FPGA内部结构之Clocking -03- 时钟管理模块(CMT)
- 【LeetCode】1020-飞地的数量
- 20_ Redis_ Sentinel mode
- Data analysis thinking analysis methods and business knowledge - business indicators
- Leetcode skimming -- count the number of numbers with different numbers 357 medium
- Party History Documentary theme public welfare digital cultural and creative products officially launched
- 彻底弄懂浏览器强缓存和协商缓存
- Solve the problem of frequent interruption of mobaxterm remote connection
- 15_ Redis_ Redis. Conf detailed explanation
- Case introduction and problem analysis of microservice
猜你喜欢

20_ Redis_ Sentinel mode

21_ Redis_ Analysis of redis cache penetration and avalanche

How to find a sense of career direction

密码学基础知识

21_Redis_浅析Redis缓存穿透和雪崩

飞凌嵌入式RZ/G2L处理器核心板及开发板上手评测

Equipped with Ti am62x processor, Feiling fet6254-c core board is launched!

LeetCode刷题——去除重复字母#316#Medium

LeetCode刷题——递增的三元子序列#334#Medium

Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568
随机推荐
飞凌嵌入式RZ/G2L处理器核心板及开发板上手评测
16_Redis_Redis持久化
. Solution to the problem of Chinese garbled code when net core reads files
怎样从微信返回的json字符串中截取某个key的值?
搭建自己的语义分割平台deeplabV3+
04.进入云原生后的企业级应用构建的一些思考
11_Redis_Hyperloglog_命令
搭载TI AM62x处理器,飞凌FET6254-C核心板首发上市!
高考录取分数线爬取
【LeetCode】189-轮转数组
【LeetCode】486-预测赢家
Bing.com網站
微信支付宝账户体系和支付接口业务流程
【Leetcode】167-两数之和II -输入有序数组
Pytoch saves tensor to Mat file
【LeetCode】1905-统计子岛屿
损失函数与正负样本分配:YOLO系列
SQL stored procedure
Summary of the first three passes of sqli Labs
06_ Stack and queue conversion