java.lang.Object
g1201_1300.s1281_subtract_the_product_and_sum_of_digits_of_an_integer.Solution

public class Solution extends Object
1281 - Subtract the Product and Sum of Digits of an Integer.<p>Easy</p> <p>Given an integer number <code>n</code>, return the difference between the product of its digits and the sum of its digits.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 234</p> <p><strong>Output:</strong> 15</p> <p><strong>Explanation:</strong></p> <p>Product of digits = 2 * 3 * 4 = 24</p> <p>Sum of digits = 2 + 3 + 4 = 9</p> <p>Result = 24 - 9 = 15</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 4421</p> <p><strong>Output:</strong> 21</p> <p><strong>Explanation:</strong></p> <p>Product of digits = 4 * 4 * 2 * 1 = 32</p> <p>Sum of digits = 4 + 4 + 2 + 1 = 11</p> <p>Result = 32 - 11 = 21</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= n <= 10^5</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • subtractProductAndSum

      public int subtractProductAndSum(int n)