Leetcode 1406 Solution

This article provides solution to leetcode question 1406 (subtract-the-product-and-sum-of-digits-of-an-integer)

https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer

Solution

class Solution:
    def subtractProductAndSum(self, n: int) -> int:
        val1 = 1
        val2 = 0

        for ch in str(n):
            val1 *= int(ch)
            val2 += int(ch)
        return val1 - val2