class Solution {
public:
vector<vector<string>> partition(string s) {
vector<vector<string>> res;
vector<string> record;
getSubStr(res, record, s, 0);
return res;
}
private:
void getSubStr(vector<vector<string>>& res, vector<string>& record, string s, int start) {
if (start == s.size()) {
res.push_back(record);
return;
}
for (int i = start; i < s.size(); i++) {
//substr的長度參數要算入自己
int len = i - start + 1;
string tmp = s.substr(start, len);
if (isPalindrome(tmp)) {
record.push_back(tmp);
getSubStr(res, record, s, i + 1);
record.pop_back();
}
}
}
bool isPalindrome(string s) {
int size = s.length();
for (int i = 0; i < size / 2; i++) {
if (s[i] != s[size - 1 - i]) {
return false;
}
}
return true;
}
};