-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path680.h
30 lines (30 loc) · 823 Bytes
/
680.h
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
class Solution {
public:
/*
* @param : a string to be split
* @return: all possible split string array
*/
vector<vector<string>> splitString(string& s) {
// write your code here
vector<string> v;
vector<vector<string>> r;
splitString(s, v, r, 0);
return r;
}
void splitString(string &s, vector<string> &v, vector<vector<string>> &r, int start){
if(start == s.size()) {
r.push_back(v);
return;
}
if(start < s.size()){
v.push_back(s.substr(start,1));
splitString(s,v,r, start+1);
v.pop_back();
}
if(start < s.size() - 1){
v.push_back(s.substr(start, 2));
splitString(s, v, r, start+2);
v.pop_back();
}
}
};