1281_subtract the Product and Sum of Digits of an Integer
Leetcode 1281 Link to heading
Given an integer number n, return the difference between the product of its digits and the sum of its digits.
Example 1:
Input: n = 234
Output: 15
Explanation:
Product of digits = 2 * 3 * 4 = 24
Sum of digits = 2 + 3 + 4 = 9
Result = 24 - 9 = 15
My solution -
func subtractProductAndSum(n int) int {
prod := 1;
sum := 0;
for n >0 {
rem := n % 10;
sum += rem;
prod *= rem;
n /= 10;
}
return prod - sum;
}