当前位置:网站首页>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;
}
};
边栏推荐
- How to avoid 7 common problems in mobile and network availability testing
- MD5 encryption
- Force deduction solution summary 2029 stone game IX
- 党史纪实主题公益数字文创产品正式上线
- Folium, diagnosis and close contact trajectory above
- College entrance examination score line climbing
- Name of institution approved in advance
- /bin/ld: 找不到 -lpam
- 04. Some thoughts on enterprise application construction after entering cloud native
- Cultural scores of summer college entrance examination
猜你喜欢
Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568
I made an istio workshop. This is the first introduction
[experience cloud] how to get the metadata of experience cloud in vscode
How to intercept the value of a key from the JSON string returned by wechat?
Finally, I understand the event loop, synchronous / asynchronous, micro task / macro task, and operation mechanism in JS (with test questions attached)
LeetCode刷题——递增的三元子序列#334#Medium
MySQL calculate n-day retention rate
Redux - detailed explanation
Two traversal sequences are known to construct binary trees
14_ Redis_ Optimistic lock
随机推荐
已知两种遍历序列构造二叉树
士官类学校名录
2279. Maximum number of backpacks filled with stones
【LeetCode】19-删除链表的倒数第N个结点
20_ Redis_ Sentinel mode
Redux - detailed explanation
Force deduction solution summarizes the lucky numbers in 1380 matrix
[leetcode] 876 intermediate node of linked list
6090. Minimax games
LeetCode刷题——验证二叉树的前序序列化#331#Medium
folium地图无法显示的问题,临时性解决方案如下
6095. Strong password checker II
PostgresSQL 流复制 主备切换 主库无读写宕机场景
Yolov5 code reproduction and server operation
Case introduction and problem analysis of microservice
[leetcode] 695 - maximum area of the island
/bin/ld: 找不到 -lcrypto
For the problem that Folium map cannot be displayed, the temporary solution is as follows
2303. 计算应缴税款总额
2022 年辽宁省大学生数学建模A、B、C题(相关论文及模型程序代码网盘下载)