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;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *