Skip to content

Commit 194568e

Browse files
authored
Create solution.cpp
1 parent 726885e commit 194568e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

FindAnagramMappings/solution.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)