-
Notifications
You must be signed in to change notification settings - Fork 0
/
241.cpp
53 lines (26 loc) · 1.07 KB
/
241.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
vector<int> diffWaysToCompute(string input) {
vector<int> result;
for (int i =0; i < input.size(); i++){
if (input[i] == '+' || input[i] == '-' || input[i] == '*'){
vector<int> left = diffWaysToCompute(input.substr(0,i));
vector<int> right = diffWaysToCompute(input.substr(i+1));
for (int j = 0; j < left.size(); j++){
for (int k =0; k < right.size(); k++){
if (input[i] == '+'){
result.push_back(left[j] + right[k]);
}
if (input[i] == '-'){
result.push_back(left[j] - right[k]);
}
if (input[i] == '*'){
result.push_back(left[j]*right[k]);
}
}
}
}
}
if (result.empty()){
result.push_back(atoi(input.c_str()));
}
return result;
}