From feb57f724d4f6459d453acb260bc4dd163e3e4f0 Mon Sep 17 00:00:00 2001 From: huisuu Date: Wed, 28 Aug 2024 19:56:46 +0900 Subject: [PATCH] 60.py --- HSKIM/51to60/60.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 HSKIM/51to60/60.py diff --git a/HSKIM/51to60/60.py b/HSKIM/51to60/60.py new file mode 100644 index 0000000..e141822 --- /dev/null +++ b/HSKIM/51to60/60.py @@ -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))