Harshad Number Finder
A Harshad number, or Niven number, is an integer that is divisible by the sum of its digits when written in base 10. Given a positive integer n, determine whether it is a Harshad number. Return true if it is a Harshad number, and false otherwise.
[ "18" ]
Explanation. The sum of the digits of 18 is 1 + 8 = 9. Since 18 is divisible by 9 (18 % 9 == 0), 18 is a Harshad number.
[ "19" ]
Explanation. The sum of the digits of 19 is 1 + 9 = 10. Since 19 is not divisible by 10, 19 is not a Harshad number.
[ "21" ]
Explanation. The sum of the digits of 21 is 2 + 1 = 3. Since 21 is divisible by 3, 21 is a Harshad number.
[ "47" ]
Explanation. The sum of the digits of 47 is 4 + 7 = 11. Since 47 is not divisible by 11, 47 is not a Harshad number.
Follow-up: Can you solve this in O(log10(n)) time complexity using a single loop to extract digits?
1 <= n <= 10^9