LC.P1281[整数的各位积和之差] 方法一:模拟123456789101112class Solution { public int subtractProductAndSum(int n) { int prod = 1, sum = 0; while (n > 0) { int x = n % 10; n /= 10; prod *= x; sum += x; } return prod - sum; }} 时间复杂度:$O(logn)$ 空间复杂度:$O(1)$