2295.cpp (428B)
1 class Solution { 2 public: 3 vector<int> arrayChange(vector<int> &nums, const vector<vector<int>> &operations) const { 4 static int position[1000001]; 5 6 for (int i = 0; i < nums.size(); i++) { 7 position[nums[i]] = i; 8 } 9 10 for (const auto &op : operations) { 11 nums[position[op[0]]] = op[1]; 12 position[op[1]] = position[op[0]]; 13 } 14 15 return nums; 16 } 17 }