Given lists A B and, and is a anagram of. is an B anagram of means are made by A B A B Rand Omizing the order of the elements in A .
We want to find a index mapping P , from A to B . A mapping P[i] = j means the i th element in A appears with at B index j .
These lists and may A B contain duplicates. If There is multiple answers, output any of them.
For example, given
A = [50, 12, 32, 46, 28], 50]b = [+]
We should return
[1, 4, 3, 2, 0]
P[0] = 1 0 as because the th element A of appears B[1] at, and P[1] = 4 because the 1 st element of A appears at B[4], and so on.
Note:
A, Bhas equal lengths in range [1, 100] .
A[i], B[i]is integers in range[0, 10^5].classSolution { Public: Vector<int> anagrammappings (vector<int>& A, vector<int>&B) {unordered_map<int,int>m; Vector<int>Res; for(inti =0; I < b.size (); i++) M[b[i]]=i; for(auto&a:a) {if(M.count (a)) {Res.push_back (m[a]); } Else{res.push_back (0); } } returnRes; } };
[Leetcode] Hash Table-760. Find Anagram Mappings