Skip to main content

3099. Harshad Number - LeetCode

class Solution:
def sumOfTheDigitsOfHarshadNumber(self, x: int) -> int:
s = 0
div = x
while div:
div, mod = divmod(div, 10)
s += mod

harshad = x % s == 0
if harshad:
return s

return -1