-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path1281.py
24 lines (24 loc) · 794 Bytes
/
1281.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
__________________________________________________________________________________________________
sample 4 ms submission
class Solution:
def subtractProductAndSum(self, n: int) -> int:
a = 0
b = 1
for i in [int(i) for i in str(n)]:
b *= i
a += i
return b - a
__________________________________________________________________________________________________
sample 8 ms submission
class Solution:
def subtractProductAndSum(self, n: int) -> int:
p, s = 1, 0
if n == 0:
return 0
while(n > 0):
t = n % 10
p *= t
s += t
n = n//10
return p-s
__________________________________________________________________________________________________