Skip to content

Commit 2cf8f44

Browse files
committed
Time: 0 ms (100.00%), Space: 40.6 MB (64.25%) - LeetHub
1 parent 2c6f462 commit 2cf8f44

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int subtractProductAndSum(int n) {
3+
int sum = 0;
4+
int product = 1;
5+
while(n > 0){
6+
int tmp = n % 10;
7+
sum += tmp;
8+
product *= tmp;
9+
//System.out.println(sum);
10+
n = n / 10;
11+
}
12+
13+
return product - sum;
14+
}
15+
}

0 commit comments

Comments
 (0)