class Solution {
public:
vector<vector<string>> partition(string s) {
vector<string> res;
vector<vector<string> > solution;
int len = s.size();
vector<vector<bool> > map(len+1, (vector<bool>(len+1,false)));
if(len == 0) return solution;
for(int i = len-1; i>=0; i--){
for(int j = i; j<len; j++){
if(s[i] == s[j] &&(j-i<2 || map[i-1][j-1])){
map[i][j] = true;
}
}
}
getSolution(res, solution, map, s, 0, len);
return solution;
}
void getSolution(vector<string> &res, vector<vector<string> > &solution, vector<vector<bool> > map, string s, int st, int e){
if(st >= e){
solution.push_back(res);
return;
}
for(int i = st; i<e; i++){
string piece = s.substr(st, i-st+1);
if(map[st][i]){
res.push_back(piece);
getSolution(res, solution, map, s, i+1, e);
}
res.pop_back();
}
return;
}
};
我得到了这个双重免费的malloc问题。但我没有在这里删除任何内存,我没有在这里看到自动释放内存? 我设置了断点,当程序进入
时问题会提示return solution;