import java.util.*;
class Solution {
public List<Integer> solution(String s) {
HashMap<Integer, Integer> map = new HashMap<>();
String[] numbers = s.replaceAll("\\{","").replaceAll("\\}", "").split(",");
for(String x: numbers){
int num = Integer.parseInt(x.trim());
map.put(num, map.getOrDefault(num, 0)+1);
}
List<Integer> keys = new ArrayList<>(map.keySet());
Collections.sort(keys, (v1, v2) -> (map.get(v2).compareTo(map.get(v1))));
ArrayList<Integer> list = new ArrayList<>();
for(Integer key : keys){
list.add(key);
}
return list;
}
}
'공부기록 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 스킬트리 (0) | 2024.02.03 |
---|---|
[프로그래머스] 최대공약수와 최소공배수 (0) | 2024.02.03 |
[프로그래머스] 피로도 (0) | 2024.01.30 |
[프로그래머스] 이진 변환 반복하기 (0) | 2023.12.25 |
[프로그래머스] 모의고사 (1) | 2023.12.23 |