Skip to content

Commit ad825c2

Browse files
committed
Create 1281.subtract-the-product-and-sum-of-digits-of-an-integer.py
1 parent d1b94ba commit ad825c2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# https://leetcode.cn/problems/subtract-the-product-and-sum-of-digits-of-an-integer
2+
3+
4+
class Solution1:
5+
'''
6+
Date: 2023.08.09
7+
Pass/Error/Bug: 1/0/0
8+
执行用时: 44 ms, 在所有 Python3 提交中击败了 42.12% 的用户
9+
内存消耗:15.48 MB, 在所有 Python3 提交中击败了 59.54% 的用户
10+
'''
11+
def subtractProductAndSum(self, n: int) -> int:
12+
n_prod = 1
13+
n_sum = 0
14+
for i in str(n):
15+
i = int(i)
16+
n_prod *= i
17+
n_sum += i
18+
19+
return n_prod - n_sum

0 commit comments

Comments
 (0)