LeetCode1281-整数的各位积和之差

LeetCode1281-整数的各位积和之差

1
2
3
4
5
6
7
8
9
10
public int subtractProductAndSum(int n) {
int x = 1;
int y = 0;
while (n != 0) {
y+=(n % 10);
x*=(n % 10);
n /= 10;
}
return x-y;
}