[Java/C++/Python] Straight Forward Solution
Complexity\nTime O(logN)\nSpace O(1)\n\n\nJava:\njava\n    public int subtractProductAndSum(int n) {\n        int sum = 0, product = 1;\n        while (n > 0) {
## **Complexity**\nTime `O(logN)`\nSpace `O(1)`\n<br>\n\n**Java:**\n```java\n    public int subtractProductAndSum(int n) {\n        int sum = 0, product = 1;\n        while (n > 0) {\n            sum += n % 10;\n            product *= n % 10;\n            n /= 10;\n        }\n        return product - sum;\n    }\n```\n\n**C++:**\n```cpp\n    int subtractProductAndSum(int n) {\n        int sum = 0, product = 1;\n        for (; n > 0; n /= 10) {\n            sum += n % 10;\n            product *= n % 10;\n        }\n        return product - sum;\n    }\n```\n\n**Python:**\nSpace `O(logN)`\n```python\n    def subtractProductAndSum(self, n):\n        A = map(int, str(n))\n        return reduce(operator.mul, A) - sum(A)\n```\n
[]