-
-
Notifications
You must be signed in to change notification settings - Fork 299
/
1281.cpp
37 lines (35 loc) · 987 Bytes
/
1281.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
__________________________________________________________________________________________________
sample 0 ms submission
class Solution {
public:
int subtractProductAndSum(int n) {
string s = to_string(n);
int sum= 0, product = 1;
for (auto i: s)
{
sum += i - '0';
product *= i - '0';
}
return (product - sum);
}
};
__________________________________________________________________________________________________
0ms
class Solution {
public:
int subtractProductAndSum(int n) {
string num = to_string(n);
int mult,add,solution;
mult=1;
add=0;
solution=0;
for(int i = 0; i<num.length();i++)
{
mult*=(num[i]-'0');
add+=(num[i]-'0');
}
solution = mult-add;
return solution;
}
};
__________________________________________________________________________________________________