LeetCode------------palindrome-partitioning(回文)
来源:互联网 发布:刀剑乱舞极化数据 编辑:程序博客网 时间:2024/06/05 16:51
题目描述
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"] ]
public:
void dfs(string s, vector<vector<string>> &res, vector<string> &path){
if (s.size()==0){
res.push_back(path);
return ; //一条深度路径结束,递归出口
}
for (int i=0; i<s.size(); i++){
int begin = 0;
int end = i;
while (begin < end){
if (s[begin] == s[end]){
++begin;
--end;
}else
break;
}
if (begin >= end){
path.push_back(s.substr(0, i+1));
dfs(s.substr(i+1,s.size()), res, path);
path.pop_back(); //逐步回退清空路径。。。。。
}
}
}
vector<vector<string>> partition(string s) {
vector<vector<string>> res;
vector<string> path;
dfs(s, res, path);
return res;
}
};
0 0
- LeetCode------------palindrome-partitioning(回文)
- [LeetCode] Palindrome Partitioning 回文分割
- leetcode【Palindrome Partitioning 回文字符串划分】
- Palindrome Partitioning 分割字符串为回文@LeetCode
- Leetcode 131 Palindrome Partitioning 回文分割
- 【LeetCode】131.Palindrome Partitioning回文划分
- LeetCode 131. Palindrome Partitioning(回文分区)
- LeetCode(Palindrome Partitioning) 将字符串分割成回文字符串
- [LeetCode]-Palindrome Partitioning 求回文分割的所有情况
- [LeetCode]Palindrome Partitioning 找出所有可能的回文组合
- LeetCode OJ 之 Palindrome Partitioning (字符串的回文分割)
- LeetCode 132. Palindrome Partitioning II(回文切分)
- leetcode 131. Palindrome Partitioning回文子串+DFS
- Palindrome Partitioning&II(回文字符串)
- 【leetcode】Palindrome Partitioning && Palindrome Partitioning II
- [LeetCode] Palindrome Partitioning && Palindrome Partitioning II
- LeetCode Palindrome Partitioning I&&Palindrome Partitioning II
- LeetCode Palindrome Partitioning, Palindrome Partitioning II
- 隔壁(贪心)
- 推荐子龙山人的emacs的教程
- IOS-—UICollectionView使用综述(二 )(基础篇--画廊展示图片,瀑布流展示图片)
- java 数据结构与算法
- ECharts图表组件之简单关系图:如何轻松实现另类站点地图且扩展节点属性实现点击节点页面跳转
- LeetCode------------palindrome-partitioning(回文)
- leetcode15&16_3Sum&4Sum
- HTTP2.0
- 数据结构
- 文档根元素 "hibernate-mapping" 必须匹配 DOCTYPE 根 "hibernate-configuration"
- undefined reference to `dlopen'错误解决
- 【java】JAVA数组初始化
- Java中ObjectOutputStream和ObjectInputStream的基本使用详解
- 关于iOS开发一些优秀的博客整理