760 Find Anagram Mappings
1. Question
A = [12, 28, 46, 32, 50]
B = [50, 12, 32, 46, 28][1, 4, 3, 2, 0]2. Implementation
3. Time & Space Complexity
Last updated
A = [12, 28, 46, 32, 50]
B = [50, 12, 32, 46, 28][1, 4, 3, 2, 0]Last updated
class Solution {
public int[] anagramMappings(int[] A, int[] B) {
if (A.length != B.length) {
return new int[0];
}
int[] res = new int[A.length];
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < B.length; i++) {
map.put(B[i], i);
}
for (int i = 0; i < A.length; i++) {
res[i] = map.get(A[i]);
}
return res;
}
}