题目来源:
LeetCode题目:3099. 哈沙德数 - 力扣(LeetCode)
解题思路:
按要求求和判断即可。
解题代码:
#python3
class Solution:def sumOfTheDigitsOfHarshadNumber(self, x: int) -> int:sumDigit=0temp=xwhile(temp!=0):sumDigit += temp%10temp=temp//10return sumDigit if x%sumDigit==0 else -1
总结:
官方题解也是直接模拟。