forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0241.cpp
27 lines (27 loc) · 775 Bytes
/
0241.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
#include <vector>
#include <cctype>
using namespace std;
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
class Solution
{
public:
vector<int> diffWaysToCompute(string input)
{
vector<int> res;
for (int i = 0; i < input.size(); i++)
{
char c = input[i];
if (ispunct(c))
{
for (int a : diffWaysToCompute(input.substr(0, i)))
{
for (int b : diffWaysToCompute(input.substr(i+1)))
{
res.push_back(c == '+' ? a+b : c == '-' ? a-b : a*b);
}
}
}
}
return res.size() ? res : vector<int>{stoi(input)};
};
};