1281. Subtract the Product and Sum of Digits of an Integer
Posted on
Description
Submission
class Solution {
public:
int subtractProductAndSum(int n) {
int t = n;
int product = 1, sum = 0;
for(; t != 0; t /= 10) {
int digit = t % 10;
sum += digit;
product *= digit;
}
return product - sum;
}
};