本所谓切割,就是找切割位置,就是组合
class Solution {
public:
vector<string> target;
vector<vector<string>> res;
vector<vector<string>> partition(string s) {
rb(s, 0);
return res;
}
void rb(string s, int start) {
// 切割完毕
if (start == s.length())
res.push_back(target);
for (int i = start; i < s.length(); i++) {
string temp = string(s.begin() + start, s.begin() + i + 1);
if (isReverse(temp)) {
target.push_back(temp);
rb(s, i + 1);
target.pop_back();
} else {
continue;
}
}
}
bool isReverse(string s) {
for (int i = 0, j = s.length() - 1; i < j; i++, j--) {
if (s[i] != s[j])
return false;
}
return true;
}
};
标签:分割,target,int,res,随想录,back,start,回文,string
From: https://www.cnblogs.com/huigugu/p/18686799