본문 바로가기

IT/코딩테스트

[Leetcode] 3099. Harshad Number

728x90

https://leetcode.com/problems/harshad-number

class Solution:
    def sumOfTheDigitsOfHarshadNumber(self, x: int) -> int:
        sum_of_digits = sum([int(i) for i in str(x)])
        
        if x % sum_of_digits == 0:
            return sum_of_digits
        else:
            return -1
728x90