Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7662675

Browse files
Subtract the Product and Sum of Digits of an Integer
1 parent ea72a8d commit 7662675

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
""" https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/ """
2+
3+
class Solution:
4+
def subtractProductAndSum(self, n):
5+
strN = str(n)
6+
product = 1
7+
sum = 0
8+
9+
for c in strN:
10+
product *= int(c)
11+
sum += int(c)
12+
13+
return product - sum
14+
15+
print(Solution().subtractProductAndSum(234))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /