Monday, February 15, 2021

Leetcode Everyday: 1281. Subtract the Product and Sum of Digits of an Integer. Easy

public class Solution {
    public int SubtractProductAndSum(int n) {
        int prod = 1;
        int sum = 0;
        for (; n > 0; n /= 10) {
            var remainder = n % 10;
            prod *= remainder;
            sum += remainder;
        }
        return prod - sum;
    }
}
Source: https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/submissions/

No comments:

Post a Comment