Skip to content

Commit 10f1d00

Browse files
authored
[20251213] PGM / 튜플 / LV2 / 이인희
1 parent 1b85533 commit 10f1d00

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public int[] solution(String s) {
5+
s = s.substring(2, s.length() - 2);
6+
String[] groups = s.split("}", "{");
7+
8+
Arrays.sort(groups, (a, b) -> a.length() - b.length());
9+
Set<Integer> used = new HashSet<Integer>();
10+
int[] answer = new int[groups.length];
11+
int index = 0;
12+
for(String group : groups){
13+
String[] nums = group.split(",");
14+
for(String num : nums){
15+
int value = Integer.parseInt(num);
16+
if(!used.contains(value)){
17+
used.add(value);
18+
answer[index++] = value;
19+
break;
20+
}
21+
}
22+
}
23+
return answer;
24+
}
25+
}

0 commit comments

Comments
 (0)