[프로그래머스](python) 두 개 뽑아서 더하기

berry ·2021년 4월 28일
0

Algorithm

목록 보기
8/77

문제


내 풀이

from itertools import combinations

def solution(numbers):
    answer = set()
    for i in list(combinations(numbers,2)):
        answer.add(sum(i))
    return sorted(answer)
    
    

+++
내장함수 combinations를 이용해서 numbers에서 숫자 2개를 뽑은 후
sum(i)로 두 수 더하고 answer에 추가
sorted로 오름차순으로 정렬

profile
Engineer

0개의 댓글