简单题重拳出击 转换心情专用题
java:
class Solution {
public int subtractProductAndSum(int n) {
int j = 1, h = 0;
while(n > 0){
int m = n % 10;
n /= 10;
j *= m;
System.out.println(j);
h += m;
System.out.println(h);
}
int ans = j - h;
return ans;
}
}
python3:
class Solution:
def subtractProductAndSum(self, n: int) -> int:
j = 1
h = 0
ans = 0
while n > 0:
m = n % 10
n = n // 10
j *= m
h += m
ans = j - h
return ans