-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
def solution(s): | ||
# 문자열에서 양쪽의 "{{"와 "}}"를 제거하고, 중괄호를 기준으로 split | ||
s = s[2:-2].split("},{") | ||
|
||
# 각 요소를 리스트로 변환 | ||
arr = [list(map(int, x.split(','))) for x in s] | ||
|
||
# 길이 기준으로 오름차순 정렬 | ||
arr.sort(key=len) | ||
|
||
answer = [] | ||
for subset in arr: | ||
for num in subset: | ||
if num not in answer: | ||
answer.append(num) | ||
break | ||
|
||
return answer | ||
|
||
s = "{{1,2,3},{2,1},{1,2,4,3},{2}}" | ||
print(solution(s)) |