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 726885e commit 194568eCopy full SHA for 194568e
FindAnagramMappings/solution.cpp
@@ -0,0 +1,17 @@
1
+class Solution {
2
+public:
3
+ vector<int> anagramMappings(vector<int>& nums1, vector<int>& nums2)
4
+ {
5
+ // Use hashmap to keep track of the indices of num2 using their value as keys
6
+ unordered_map<int, int> hashmap;
7
+ for (int i=0; i<nums2.size(); i++)
8
+ hashmap[nums2.at(i)] = i;
9
+
10
+ // Use mapping vector to map num1 to num2
11
+ vector<int> mapping(nums1.size());
12
+ for (int i=0; i<nums1.size(); i++)
13
+ mapping.at(i) = hashmap[nums1.at(i)];
14
15
+ return mapping;
16
+ }
17
+};
0 commit comments