문제 링크

문제 풀이

  1. input : string => array => sort
  2. answer : set => array

전체 코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function solution(s) {
const sets = s
.split("}")
.reduce((a, b) => {
b = b.replace("{{", "").replace(",{", "");
if (b.length > 0) a.push(b.split(","));
return a;
}, [])
.sort((a, b) => a.length - b.length);

let answer = new Set([]);

while (sets.length > 0) {
const temp = sets.shift();
while (temp.length > 0) {
answer.add(parseInt(temp.shift()));
}
}

return [...answer];
}