-
Notifications
You must be signed in to change notification settings - Fork 0
/
p131.cpp
48 lines (44 loc) · 1000 Bytes
/
p131.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
46
47
48
#include <bits/stdc++.h>
using namespace std;
class Solution
{
private:
bool isPelindrome(string &s, int start, int end)
{
while (start < end)
{
if (s[start++] != s[end--])
return false;
}
return true;
}
void solve(int index, string &s, vector<string> &seqs, vector<vector<string>> &result)
{
if (index == s.size())
{
result.push_back(seqs);
return;
}
for (int i = index; i < s.size(); i++)
{
if (isPelindrome(s, index, i))
{
seqs.push_back(s.substr(index, i - index + 1));
solve(index + 1, s, seqs, result);
seqs.pop_back();
}
}
}
public:
vector<vector<string>> partition(string s)
{
vector<vector<string>> result;
vector<string> seqs;
solve(0, s, seqs, result);
return result;
}
};
int main()
{
return 0;
}