|
1 | 1 | package com.fishercoder.solutions;
|
2 | 2 |
|
3 |
| -/** |
4 |
| - * 760. Find Anagram Mappings |
5 |
| - * |
6 |
| - * Given two lists Aand B, and B is an anagram of A. B is an anagram of A means B is made by randomizing the order of the elements in A. |
7 |
| - * We want to find an index mapping P, from A to B. A mapping P[i] = j means the ith element in A appears in B at index j. |
8 |
| - * These lists A and B may contain duplicates. If there are multiple answers, output any of them. |
9 |
| -
|
10 |
| - For example, given |
11 |
| -
|
12 |
| - A = [12, 28, 46, 32, 50] |
13 |
| - B = [50, 12, 32, 46, 28] |
14 |
| -
|
15 |
| - We should return |
16 |
| - [1, 4, 3, 2, 0] |
17 |
| - as P[0] = 1 because the 0th element of A appears at B[1], and P[1] = 4 because the 1st element of A appears at B[4], and so on. |
18 |
| -
|
19 |
| - Note: |
20 |
| -
|
21 |
| - A, B have equal lengths in range [1, 100]. |
22 |
| - A[i], B[i] are integers in range [0, 10^5]. |
23 |
| - */ |
24 | 3 | public class _760 {
|
25 |
| - public static class Solution1 { |
26 |
| - public int[] anagramMappings(int[] A, int[] B) { |
27 |
| - int[] result = new int[A.length]; |
28 |
| - for (int i = 0; i < A.length; i++) { |
29 |
| - for (int j = 0; j < B.length; j++) { |
30 |
| - if (A[i] == B[j]) { |
31 |
| - result[i] = j; |
32 |
| - } |
| 4 | + public static class Solution1 { |
| 5 | + public int[] anagramMappings(int[] A, int[] B) { |
| 6 | + int[] result = new int[A.length]; |
| 7 | + for (int i = 0; i < A.length; i++) { |
| 8 | + for (int j = 0; j < B.length; j++) { |
| 9 | + if (A[i] == B[j]) { |
| 10 | + result[i] = j; |
| 11 | + } |
| 12 | + } |
| 13 | + } |
| 14 | + return result; |
33 | 15 | }
|
34 |
| - } |
35 |
| - return result; |
36 | 16 | }
|
37 |
| - } |
38 | 17 | }
|
0 commit comments