-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path分割回文串
30 lines (29 loc) · 760 Bytes
/
分割回文串
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Solution {
public:
vector<vector<string>> result;
vector<string> v;
bool isPalindrome(const std::string& str) {
std::string reversedStr = str;
std::reverse(reversedStr.begin(), reversedStr.end());
return (str == reversedStr);
}
void back(string &s, int k, string s1){
if(k==s.size()){
result.push_back(v);
return;
}
for(int i=k;i<s.size();i++){
s1+=s[i];
string rev=s1;
if(isPalindrome(s1)){
v.push_back(s1);
back(s, i+1, "");
v.pop_back();
}
}
}
vector<vector<string>> partition(string &s) {
back(s, 0, "");
return result;
}
};