1281. Subtract the Product and Sum of Digits of an Integer 發表於 2023-02-13 | 分類於 leetcode problemsolution123456789101112class Solution {public: int subtractProductAndSum(int n) { int prod = 1, sum = 0; while(n){ prod *= (n%10); sum+=(n%10); n/=10; } return prod - sum; }}; analysis time complexity O(logn) sparse complexity O(1)