> For the complete documentation index, see [llms.txt](https://heunnajo.gitbook.io/algorithms-problem-solving-skills/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://heunnajo.gitbook.io/algorithms-problem-solving-skills/algorithm-problems/find-anagrams-mapping.md).

# Find Anagrams Mapping

> Map 모른다고 겁먹지 말기. Map으로 푸는 문제 치고는 쉬운 문제!

> **Example**\
> **Input : int\[ ] A =** {11,27,45,31,50}; **int\[ ] B** = {50,11,31,45,27};\
> **Output :** \[1 4 3 2 0]

**자료구조** : **Map** 이용

**알고리즘**\
1\. 담을 그릇 생성 : Map과 정답 배열\
2\. Map에 B배열을 담는다. (key,value) = (B\[i],i). 왜냐하면 **찾고자하는 것은 원소값**이고, 원소값이 몇번째 인덱스인지(value)를 얻기 위해!\
3\. Map에서 A의 원소가 몇번째인지를 정답 배열에 넣는다. 정답 배열을 리턴한다.

```java
public static void main(String[] args) {
			int[] A = {12, 28, 46, 32, 50};
			int[] B = {50, 12, 32, 46, 28};
			int [] result = anagramMappings(A, B);
			print(result);
		}
		
		public static void print(int[] result) {
			for(int i=0; i< result.length; i++) {
				System.out.print(result[i]+" ");
			}
		}

		public static int[] anagramMappings(int[] A, int[] B) {
		    int leng = A.length;
		    int[] res = new int[leng];
        HashMap<Integer,Integer> map = new HashMap<>();
		    for(int i=0;i<leng;i++){
		        map.put(B[i],i);
		    }
		    for(int i=0;i<leng;i++){
		        res[i] = map.get(A[i]);
		    }        
		    return res;
		}
```
