给你一个整数 n
,请你帮忙计算并返回该整数「各位数字之积」与「各位数字之和」的差。
1281. 整数的各位积和之差 – 力扣(Leetcode)

思路:
求积,和,做减法。
python3实现:
class Solution:
def subtractProductAndSum(self, n: int) -> int:
str_b = str(n)
ji = 1
he = 0
for i in str_b:
ji *= int(i)
he += int(i)
return ji - he
