[Leetcode] 5279. Subtract the Product and Sum of Digits of an Integer

 

 

class Solution {
    public int subtractProductAndSum(int n) {
        int productResult = 1;
        int sumResult = 0;
        do {
            int currentval = n % 10;
            productResult *= currentval;
            sumResult += currentval;
            n /= 10;
        }while(n > 0);
        
        return productResult - sumResult;
    }
}

 

posted on 2019-12-08 11:42  seako  阅读(161)  评论(0编辑  收藏  举报