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