当前位置:网站首页>6092. Replace elements in the array
6092. Replace elements in the array
2022-07-02 15:40:00 【Laver (nori)】
class Solution {
public:
vector<int> arrayChange(vector<int>& nums, vector<vector<int>>& operations) {
// preservation nums Subscript information of all elements in
// key: value ; value: Subscript
map<int, int> map;
for(int i = 0; i < nums.size(); i++){
// Insert the value and the corresponding subscript
map.emplace(nums[i], i);
}
// Traverse all operations
for(int i = 0; i < operations.size(); i++){
auto it = map.find(operations[i][0]);
// Because it must exist , So there is no need to judge
// if(it == end(map)){
// continue;
// }
// Replace the value of the corresponding position
int val = operations[i][1];
nums[it->second] = val;
// Update or insert new elements and corresponding subscripts
map[val] = it->second;
}
return nums;
}
};边栏推荐
- 13_ Redis_ affair
- Leetcode skimming -- sum of two integers 371 medium
- Leetcode skimming - remove duplicate letters 316 medium
- Leetcode skimming -- incremental ternary subsequence 334 medium
- Force deduction solution summarizes the lucky numbers in 1380 matrix
- Engineer evaluation | rk3568 development board hands-on test
- How to intercept the value of a key from the JSON string returned by wechat?
- Bing. Com website
- Build your own semantic segmentation platform deeplabv3+
- Summary of the first three passes of sqli Labs
猜你喜欢

密码学基础知识

【LeetCode】1905-统计子岛屿

Solve the problem of frequent interruption of mobaxterm remote connection

Markdown tutorial

How to choose a third-party software testing organization for automated acceptance testing of mobile applications

LeetCode刷题——统计各位数字都不同的数字个数#357#Medium

Leetcode skimming - remove duplicate letters 316 medium

Loss function and positive and negative sample allocation: Yolo series

16_ Redis_ Redis persistence

6.12 critical moment of Unified Process Platform
随机推荐
Real estate market trend outlook in 2022
[network security] network asset collection
Case introduction and problem analysis of microservice
20_ Redis_ Sentinel mode
How to avoid 7 common problems in mobile and network availability testing
List of sergeant schools
彻底弄懂浏览器强缓存和协商缓存
[leetcode] 876 intermediate node of linked list
. Solution to the problem of Chinese garbled code when net core reads files
SQL transaction
15_ Redis_ Redis. Conf detailed explanation
LeetCode刷题——统计各位数字都不同的数字个数#357#Medium
【LeetCode】1140-石子游戏II
[leetcode] 167 - sum of two numbers II - enter an ordered array
【LeetCode】1905-统计子岛屿
终于搞懂了JS中的事件循环,同步/异步,微任务/宏任务,运行机制(附笔试题)
Folium, diagnosis and close contact trajectory above
Thoroughly understand browser strong cache and negotiation cache
Markdown tutorial
二叉树前,中,后序遍历