zzunsik 2021. 7. 28. 23:27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import java.util.*;
class Solution {
    public int[] solution(String s) {
        int[] answer = {};
        // 숫자 분리
        String[] arr = s.split("\\{\\{|\\}\\}|\\},\\{|,");
        Map<String, Integer> map = new HashMap<String, Integer>();
 
        // 숫자 빈도 저장
        for (int i = 1; i < arr.length; i++)
            map.put(arr[i], map.getOrDefault(arr[i], 0+ 1);
        answer = new int[map.size()];
 
        // 숫자 빈도에 따른 위치 설정
        for (String key : map.keySet()) {
            answer[map.size() - map.get(key)] = Integer.parseInt(key);
        }
        return answer;
    }
}
cs

튜플의 중복을 제거하는건 쉬웠지만 위치를 설정하는 것이 까다로웠다.

이는 튜플의 빈도를 이용하여 해결하였다.