class Solution {
public:
vector<vector<string>> result;
vector<string> temp;
string path;
// 判断是否为回文子串
bool is_huiwen(string &path){
int i = 0;
int j = path.size() - 1;
while(i <= j){
if(path[i] == path[j]){
i++;
j--;
}else{
return false;
}
}
return true;
}
void doBack(int& size, string& s, int start){
if(start == size){
result.push_back(temp);
// temp.clear();
return;
}
for(int i = start; i < size; i++){
path += s[i];
if(is_huiwen(path)){
string ss = path;
temp.push_back(path);
path = "";
doBack(size, s, i + 1);
path = ss;
temp.pop_back();
}
}
}
vector<vector<string>> partition(string s) {
int size = s.size();
doBack(size, s, 0);
return result;
}
};
分割回文串
最新推荐文章于 2024-05-07 15:50:45 发布