leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1281.cpp (287B)


0 class Solution {
1 public:
2 int subtractProductAndSum(int n) const {
3 int product = 1, sum = 0;
5 do {
6 const int digit = n % 10;
7 product *= digit;
8 sum += digit;
9 } while ((n /= 10) > 0);
11 return product - sum;
12 }
13 };