Python 3 (20ms) | 3 Solutions | Fastest Iterative & One-Liners | Super Easy
1 - Normal Iterative Solution ( 25ms ) :-\n\nclass Solution:\n    def subtractProductAndSum(self, n: int) -> int:\n        p,s=1,0\n        while n!=0:\n       
***1 - Normal Iterative Solution ( 25ms ) :-***\n```\nclass Solution:\n    def subtractProductAndSum(self, n: int) -> int:\n        p,s=1,0\n        while n!=0:\n            p*=(n%10)\n            s+=(n%10)\n            n//=10\n        return p-s\n```\n\n***2 - Using Prod & Sum function [One-Liner] ( 20ms ) :-***\n*"prod" method from the math standard library was added in Python 3.8 onwards.*\n\n```\nclass Solution:\n    def subtractProductAndSum(self, n: int) -> int:\n        return prod(list(map(int, str(n))))-sum(list(map(int, str(n))))\n```\n*Same in 2 Lines:-*\n```\nclass Solution:\n    def subtractProductAndSum(self, n: int) -> int:\n        arr = list(map(int, str(n)))\n        return prod(arr)-sum(arr)\n```\n\n***3 - Using Reduce & Multiplication Function ( Takes 30ms ) :-***\n\n```\nclass Solution:\n    def subtractProductAndSum(self, n: int) -> int:\n        arr = list(map(int, str(n)))\n        return reduce(operator.mul, arr) - sum(arr)\n```
['Python', 'Python3']