본문 바로가기

알고리즘/프로그래머스

[프로그래머스] 튜플

728x90

https://school.programmers.co.kr/learn/courses/30/lessons/64065

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

🤔 문제분석

데이터를 전처리하고 리스트의 크기 기준으로 정렬한뒤 순회하면서 현재 존재하지 않는 값을 넣어주면 된다.

💻 코드

def solution(s :str):
    temp = s.lstrip('{').rstrip('}').split("},{")
    
    for i in range(len(temp)):
        temp[i] = list(map(int, temp[i].split(',')))
        
    temp.sort(key=len)
    answer = []
    
    for t in temp:
        for k in t:
            if k not in answer:
                answer.append(k)
    
    return answer
728x90