[프로그래머스] 하샤드 수

SEUNGCHAN BAEK·2021년 3월 11일
0

def solution(x):
    answer = False
    total = 0
    total = sum([int(i) for i in str(x)])

    if x % total == 0:
        answer = True
    return answer

다른사람 풀이 참고

def solution(x):
    return x % sum([int(i) for i in str(x)]) == 0

이렇게 answer = False 를 담지 않고 한번에 True, False를 return 할 수 있다.

profile
백엔드 개발자가 되는 그날까지

0개의 댓글

Powered by GraphCDN, the GraphQL CDN