-
Notifications
You must be signed in to change notification settings - Fork 0
/
palindromepart.cpp
45 lines (39 loc) · 1.07 KB
/
palindromepart.cpp
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class Solution {
public:
vector<vector<string>> results;
string str;
bool testpart(string teststr){
string rev = teststr;
reverse(teststr.begin(),teststr.end());
if(rev == teststr)
return true;
else
return false;
}
void test(int start,vector<string> res){
if(start == str.size()){
results.push_back(res);
return;
}
for(int i = start; i < str.size(); i ++){
string teststr = str.substr(start,i-start+1);
if(testpart(teststr)){
res.push_back(teststr);
test(i+1,res);
res.pop_back();
}
}
return;
}
vector<vector<string>> partition(string s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
results.clear();
str = s;
if(s.size() == 0)
return results;
vector<string> res;
test(0,res);
return results;
}
};