This is a simple problem. We just need to calculate sum and product of each digits in the given number.
class Solution:
def subtractProductAndSum(self, n: int) -> int:
digits = [int(c) for c in str(n)]
product = 1
for d in digits:
product *= d
return product - sum(digits)