}returnprod -sum; } }; Github 同步地址: https://github.com/grandyang/leetcode/issues/1281 参考资料: https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/ https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/discuss/446372/JavaC...
题目如下: Given an integer numbern, return the difference between the product of its digits and the sum of its digits. Example 1: Input: n = 234 Output: 15 Explanation: Product of digits = 2 * 3 * 4 = 24 Sum of digits = 2 + 3 + 4 = 9 Result = 24 - 9 = 15 Example 2: ...
Can you solve this real interview question? Subtract the Product and Sum of Digits of an Integer - Given an integer number n, return the difference between the product of its digits and the sum of its digits. Example 1: Input: n = 234 Output: 15 E
1281. Subtract the Product and Sum of Digits of an Integer # 题目 # Given an integer number n, return the difference between the product of its digits and the sum of its digits. Example 1: Input: n = 234 Output: 15 Explanation: Product of digits = 2 *
1281. Subtract the Product and Sum of Digits of an Integer* https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/ 题目描述 Given an integer number n, return the difference between the product of its digits and the sum of its di...
int subtractProductAndSum(int n) { int sum = 0; int product = 1; while (n > 0) { sum += n % 10; product *= n % 10; n /= 10; } return product - sum; } }; The C++ code above requires O(1) constant space. And in Python, you could convert the integer into string, ...
Given an integer number n, return the difference between the product of its digits and the sum of its digits. Example 1: Input: n = 234 Output: 15 Explanation: Product of digits = 2 * 3 * 4 = 24 Sum of digits = 2 + 3 + 4 = 9 Result = 24 - 9 = 15 ...
[LeetCode] 1281. Subtract the Product and Sum of Digits of an Integer 2019-12-21 02:35 −Given an integer number n, return the difference between the product of its digits and the sum of its digits. Example 1: Input: n = 234 Ou... ...
LeetCode 1281. Subtract the Product and Sum of Digits of an Integer 减去整数位数的乘积和和 (Easy) Given an integer number n, return the difference between the product of its digits and the sum of its digits. 给定整数n,返回其数字乘积与数字总和之间的差。
附leetcode链接:https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/ 1281. Subtract the Product and Sum of Digits of an Integer Given an integer number n, return the difference between the product of its digits and the sum of its digits. ...