[C++] 100% time, ~80% space - time => linear to number of digits; space => constant
I just produce slicing the last digit off n until it boils down to 0, all the while updating the product p and the sum s of the digits.\n\nNote - I am pretty su
I just produce slicing the last digit off `n` until it boils down to `0`, all the while updating the product `p` and the sum `s` of the digits.\n\nNote - I am pretty sure interviewers seeing you convert the number to string, splitting it into `char`s, converting them back to numbers, etc won\'t be that impressed.\n\nThe code:\n\n```cpp\nclass Solution {\npublic:\n    int subtractProductAndSum(int n) {\n        int p = 1, s = 0, t;\n        while (n) {\n            t = n % 10;\n            p *= t;\n            s += t;\n            n /= 10;\n        }\n        return p - s;\n    }\n};\n```
['C', 'C++']