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/
"Simplicity can't be bought later, it must be earned from the start" -- DB
Monday, February 15, 2021
Leetcode Everyday: 1281. Subtract the Product and Sum of Digits of an Integer. Easy
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment