We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5da9421 commit 835a30aCopy full SHA for 835a30a
Medium/Replace Elements in an Array.java
@@ -0,0 +1,14 @@
1
+class Solution {
2
+ public int[] arrayChange(int[] nums, int[][] operations) {
3
+ Map<Integer, Integer> indexMap = new HashMap<>();
4
+ for (int i = 0; i < nums.length; i++) {
5
+ indexMap.put(nums[i], i);
6
+ }
7
+ for (int[] operation : operations) {
8
+ int prevElementIdx = indexMap.get(operation[0]);
9
+ indexMap.put(operation[1], prevElementIdx);
10
+ nums[prevElementIdx] = operation[1];
11
12
+ return nums;
13
14
+}
0 commit comments