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"]
]
class Solution { public: vector<vector<string> >res; vector<string>v; vector<vector<string>> partition(string s) { dfs(s); return res; } void dfs(string s){ if(s.size() < 1){ res.push_back(v); return; } for(int i = 0;i < s.size();i ++){ int beg = 0,end = i; while(beg < end){ if(s[beg] == s[end]){ beg ++; end --; } else break; } if(beg >= end){ v.push_back(s.substr(0,i + 1)); dfs(s.substr(i+1)); v.pop_back(); } } } };
本文介绍了如何将字符串划分为多个回文子串,并提供了相应的算法实现。
293

被折叠的 条评论
为什么被折叠?



