当前位置:网站首页>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;
}
};边栏推荐
- 【LeetCode】977-有序数组的平方
- Party History Documentary theme public welfare digital cultural and creative products officially launched
- Equipped with Ti am62x processor, Feiling fet6254-c core board is launched!
- LeetCode刷题——递增的三元子序列#334#Medium
- [leetcode] 695 - maximum area of the island
- 语义分割学习笔记(一)
- 20_Redis_哨兵模式
- Leetcode question brushing - parity linked list 328 medium
- Summary of the first three passes of sqli Labs
- 党史纪实主题公益数字文创产品正式上线
猜你喜欢

Leetcode question brushing - parity linked list 328 medium

04_ Stack

LeetCode刷题——奇偶链表#328#Medium

Markdown tutorial

损失函数与正负样本分配:YOLO系列

Case introduction and problem analysis of microservice

Download blender on Alibaba cloud image station

(Video + graphic) machine learning introduction series - Chapter 5 machine learning practice

Steps for Navicat to create a new database

Leetcode skimming -- count the number of numbers with different numbers 357 medium
随机推荐
高考录取分数线爬取
Let your HMI have more advantages. Fet-g2ld-c core board is a good choice
yolo格式数据集处理(xml转txt)
17_Redis_Redis发布订阅
How to find a sense of career direction
自定义异常
02_线性表_顺序表
Semantic segmentation learning notes (1)
百变大7座,五菱佳辰产品力出众,人性化大空间,关键价格真香
(Video + graphic) machine learning introduction series - Chapter 5 machine learning practice
Bing.com網站
Guangzhou Emergency Management Bureau issued a high temperature and high humidity chemical safety reminder in July
Pytoch saves tensor to Mat file
[leetcode] 189 rotation array
【LeetCode】876-链表的中间结点
Build your own semantic segmentation platform deeplabv3+
MySQL calculate n-day retention rate
Data analysis thinking analysis methods and business knowledge - business indicators
【LeetCode】200-岛屿数量
【LeetCode】977-有序數組的平方