Given a string s, partition s such that every substring of the partition is a palindrome.
Return all possible palindrome partitioning of s.
For example,
given s = "aab"
,
Return
[ ["aa","b"], ["a","a","b"] ]
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 |
class
Solution { private : vector<vector<string> > res; public : void
DFS(string s, vector<string> &ans) { if (s.size()<1) { res.push_back(ans); return ; } for ( int
i=0;i<s.size();i++) { int
start=0; int
end=i; while (start<end) { if (s[start]==s[end]) { start++; end--; } else
break ; } if (start>=end) { ans.push_back(s.substr(0,i+1)); DFS(s.substr(i+1),ans); ans.pop_back(); } } } vector<vector<string>> partition(string s) { res.clear(); vector<string> ans; DFS(s,ans); return
res; } }; |
[LeetCode]Palindrome Partitioning,布布扣,bubuko.com
[LeetCode]Palindrome Partitioning
原文:http://www.cnblogs.com/Rosanna/p/3597364.html