Practice Harshad Number
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
An integer divisible by the sum of its digits is said to be a Harshad number. You are given an integer x. Return the sum of the digits of x if x is a Harshad number, otherwise, return -1.
Source: Harshad Number on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
x = 18
Output
9
# Example 2
Input
x = 23
Output
-1
Constraints
1 <= x <= 100
Related LeetCode Problems
Practice more problems similar to Harshad Number.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.