Simple approach- C++ (BEATS 100% RUNTIME)
Code\n\nclass Solution {\npublic:\n    int subtractProductAndSum(int n) {\n        int sum=0; int prod=1;\n        while(n!=0)\n        {\n            int dig=n
# Code\n```\nclass Solution {\npublic:\n    int subtractProductAndSum(int n) {\n        int sum=0; int prod=1;\n        while(n!=0)\n        {\n            int dig=n%10;\n            sum+=dig;\n            prod*=dig;\n            n/=10;\n        }\n        return prod-sum;\n    }\n};\n```
['C++']