1281. Subtract the Product and Sum of Digits of an Integer
1 2 3 4 5 6 7 8 9 10 11 12 13
| class Solution { public int subtractProductAndSum(int n) { int product = 1, sum = 0; while (n > 0) { int num = n % 10; n /= 10; product *= num; sum += num; }
return product - sum; } }
|
References
1281. Subtract the Product and Sum of Digits of an Integer