튜플 (Level 2)

정은경·2020년 11월 1일
0

1. 문제



2. 나의 풀이

import heapq

def solution(s):
    answer = []
    stack = []
    temp = []
    num_list = []
    for i in s:
        temp.append(i)
        if i=='}':
            temp.append(i)
            stack.append(''.join(temp))
            temp = []
    # print(stack)
    for chunk in stack:
        temp = chunk.split(",")
        nums = []
        for t in temp:
            t = t.replace('{','')
            t = t.replace('}','')
            if t != '':
                nums.append(int(t))
        if nums:
            heapq.heappush(num_list, (len(nums),nums))
    while num_list:
        ns = heapq.heappop(num_list)[1]
        # print(ns, end=", ")
        for n in ns:
            if n not in answer:
                answer.append(n)
    return answer

3. 남의 풀이



4. 느낀 점

profile
#의식의흐름 #순간순간 #생각의스냅샷

0개의 댓글