[LeetCode]Palindrome Partitioning 找出所有可能的回文组合
来源:互联网 发布:估值建模 知乎 编辑:程序博客网 时间:2024/05/29 06:56
给定一个串,分割该串,使得每个子串都是回文串。找出所有可能的组合。
方法:暴搜+回溯
class Solution {public:int *b,n;vector<vector<string> >ans;void dfs(int id,string &s,int len){if(id>=n){if(len>0){vector<string>vt;vt.push_back(s.substr(0,b[0]+1));for(int i=1;i<len;++i){vt.push_back(s.substr(b[i-1]+1,b[i]-b[i-1]));}ans.push_back(vt);}return;}int j,k;b[len]=id;dfs(id+1,s,len+1);for(j=id+1;j<n;++j){for(k=0;id+k<j-k&&s[id+k]==s[j-k];++k);if(id+k>=j-k){b[len]=j;dfs(j+1,s,len+1);}}}vector<vector<string> > partition(string s) {n=s.size();if(n==0)return ans; if(n==1){ vector<string>vt; vt.push_back(s);ans.push_back(vt);return ans;}b=new int[n];dfs(0,s,0);return ans; }};
0 0
- [LeetCode]Palindrome Partitioning 找出所有可能的回文组合
- Palindrome Partitioning 回文串分割,求所有可能的分割
- [LeetCode]-Palindrome Partitioning 求回文分割的所有情况
- LeetCode------------palindrome-partitioning(回文)
- leetcode:Palindrome Partitioning (字符串分割成回文串的所有方式) 【面试算法题】
- [LeetCode] Palindrome Partitioning 回文分割
- LeetCode OJ 之 Palindrome Partitioning (字符串的回文分割)
- leetcode【Palindrome Partitioning 回文字符串划分】
- Palindrome Partitioning 分割字符串为回文@LeetCode
- Leetcode 131 Palindrome Partitioning 回文分割
- 【LeetCode】131.Palindrome Partitioning回文划分
- LeetCode 131. Palindrome Partitioning(回文分区)
- 分割成回文需要的最小分割数 Palindrome Partitioning II @LeetCode
- LeetCode(Palindrome Partitioning) 将字符串分割成回文字符串
- LeetCode 132. Palindrome Partitioning II(回文切分)
- leetcode 131. Palindrome Partitioning回文子串+DFS
- Palindrome Partitioning&II(回文字符串)
- 【leetcode】Palindrome Partitioning && Palindrome Partitioning II
- 第十一周项目二求最大公约数
- 抓网页入门
- C#泛型详解
- spring for android
- U-Boot启动过程--详细版的完全分析
- [LeetCode]Palindrome Partitioning 找出所有可能的回文组合
- 深度学习(Deep Learning)综述
- 第十一周项目4
- ZOJ 2680 Clock(数学)
- 机器学习(Machine Learning)&深度学习(Deep Learning)资料
- 用求n!来比较while和for的不同
- IT 成长之路
- FMDB 简化 SQLite
- Android 异步加载网络图片并缓存到本地 软引用 学习分享