
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> temp;
vector<vector<string>> result;
int length=s.length();
splitStringHelper(0,s,temp,result);
return result;
}
void splitStringHelper(int start,string& s,vector<string> temp,vector<vector<string>>& result) {
if(start>=s.length()) {
result.push_back(temp);
return;
}
vector<string> tmp=temp;
tmp.push_back(s.substr(start,1));
splitStringHelper(start+1,s,tmp,result);
if(start+2<=s.length()) {
temp.push_back(s.substr(start,2));
splitStringHelper(start+2,s,temp,result);
}
}
};
浙公网安备 33010602011771号