πŸ—οΈ Algorithm/⬛ ν”„λ‘œκ·Έλž˜λ¨ΈμŠ€

[Programmers] [μ›”κ°„ μ½”λ“œ μ±Œλ¦°μ§€ μ‹œμ¦Œ1] [Python] Level1_두 개 λ½‘μ•„μ„œ λ”ν•˜κΈ°

Dbswnstjd 2022. 3. 16. 20:36

https://programmers.co.kr/learn/courses/30/lessons/68644

 

μ½”λ”©ν…ŒμŠ€νŠΈ μ—°μŠ΅ - 두 개 λ½‘μ•„μ„œ λ”ν•˜κΈ°

μ •μˆ˜ λ°°μ—΄ numbersκ°€ μ£Όμ–΄μ§‘λ‹ˆλ‹€. numbersμ—μ„œ μ„œλ‘œ λ‹€λ₯Έ μΈλ±μŠ€μ— μžˆλŠ” 두 개의 수λ₯Ό 뽑아 λ”ν•΄μ„œ λ§Œλ“€ 수 μžˆλŠ” λͺ¨λ“  수λ₯Ό 배열에 μ˜€λ¦„μ°¨μˆœμœΌλ‘œ λ‹΄μ•„ return ν•˜λ„λ‘ solution ν•¨μˆ˜λ₯Ό μ™„μ„±ν•΄μ£Όμ„Έμš”. μ œν•œ

programmers.co.kr

풀이

# ν”„λ‘œκ·Έλž˜λ¨ΈμŠ€ 1단계 - 두 개 λ½‘μ•„μ„œ λ”ν•˜κΈ°
from itertools import combinations
def solution(numbers):
    answer = set()
    for i in list(combinations(numbers, 2)):
        answer.add(sum(i)) 
    return sorted(answer)