Subtract the Product and Sum of Digits of an Integer
给一个数, 返回它的每个位上的数的积和和的差.
1 2 3 4 5 6 7 8 9 10 11 12 |
class Solution { public int subtractProductAndSum(int n) { int p = 1; int s = 0; while(n > 0) { p *= n % 10; s += n % 10; n /= 10; } return p - s; } } |