2021.01.31 연습

 

  • 사용언어 : java

 


class Solution {
    public int subtractProductAndSum(int n) {
        
        int product = 1;
        int sum = 0;
        
        
        while ( n != 0) { 
            product = product * (n%10);
            sum = sum + (n%10);
            n = n/10;
        }
        
        
        return product - sum;
    }
}


Runtime: 0 ms, faster than 100.00% of Java online submissions for Subtract the Product and Sum of Digits of an Integer. Memory Usage: 36.2 MB, less than 18.37% of Java online submissions for Subtract the Product and Sum of Digits of an Integer.