public int[] solution(String s) {
String[] elements = extractElements(s);
List<Integer> resultList = new ArrayList<>();
Arrays.sort(elements, (s1, s2) -> s1.length() - s2.length());
for (String element : elements) {
String[] values = element.split(",");
for (String value : values) {
int intValue = Integer.parseInt(value);
if (!resultList.contains(intValue)) {
resultList.add(intValue);
}
}
}
return resultList.stream().mapToInt(Integer::intValue).toArray();
}
private String[] extractElements(String s) {
return s.substring(2, s.length() - 2).split("},\\{");
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/64065