leetcode1281 整数的各位积和之差

 

 

class Solution {
public:
    int subtractProductAndSum(int n) {
        int add=0; int prod=1;
        while(n>0){
            int r=n%10;
            n/=10;
            prod*=r;
            add+=r;
        }
        int res=prod-add;
        return res;
    }
};

 

 

posted @ 2019-12-09 10:10  Joel_Wang  阅读(216)  评论(0编辑  收藏  举报