# ★★☆☆☆ 튜플
# 구현코드
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class Solution {
public Integer[] solution(String s) {
s = s.substring(1,s.length()-1);
ArrayList<String> list = new ArrayList<>();
for(int i = 0; i < s.length(); i++){
String value = "";
if(s.charAt(i) == '{'){
while (s.charAt(++i) != '}'){
value = value + s.charAt(i);
}
list.add(value);
}
}
String[] values = list.toArray(new String[0]);
Arrays.sort(values,(o1,o2) -> o1.length() > o2.length() ? 1 : -1);
ArrayList<Integer> tuple = new ArrayList<>();
Set<Integer> set = new HashSet<>();
for(String value : values){
String[] splitValue = value.split(",");
for(String v : splitValue){
if(!set.contains(Integer.parseInt(v))){
tuple.add(Integer.parseInt(v));
set.add(Integer.parseInt(v));
}
}
}
return tuple.toArray(new Integer[0]);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39