코드
def solution(s):
answer = []
res={}
tmp=''
lst=[]
for i in s:
if i.isdecimal():
tmp+=i
elif i==',' and tmp:
lst.append(int(tmp))
tmp=''
elif i=='}' and tmp:
lst.append(int(tmp))
res[len(lst)]=lst
lst=[]
tmp=''
res=sorted(res.items())
for i in res:
for j in i[1]:
if j not in answer:
answer.append(j)
return answer
다른 사람의 풀이
def solution(s):
answer=[]
s1=s.lstrip('{').rstrip('}').split('},{')
new_s=[]
for i in s1:
new_s.append(i.split(','))
new_s.sort(key=len)
for i in new_s:
for j in i:
if int(j) not in answer:
answer.append(int(j))
return answer