[LeetCode] 1281. Subtract the Product and Sum of Digits of an Integer
Python
class Solution:
def subtractProductAndSum(self, n: int) -> int:
temp = list(map(int, ' '.join(str(n)).split()))
product_of_digits = 1
sum_of_digits = 0
for i in temp:
product_of_digits *= i
sum_of_digits += i
return product_of_digits - sum_of_digits
댓글남기기