코딩테스트/Python

[프로그래머스/Python] 없는 숫자 더하기

짐니♡ 2025. 9. 24. 00:33

 

진짜 쉬운풀이

0부터 9까지 합이 45라는걸 아는 경우는 쉽게 구할 수 있음

def solution(numbers):


     return 45 - sum(numbers)

 

 

def solution(numbers):

    total = 0
    for i in range(0,10):
        if i not in numbers:
            total += i
    return total

 

for문으로 푸는 경우

numbers에 없는 수를 구할때는 if i not in numbers를 사용하면 쉽게 구할 수 있음 ! ㅠ