131. Palindrome Partitioning(字符串,dfs回溯)
来源:互联网 发布:剑网三捏脸数据成女 编辑:程序博客网 时间:2024/05/29 09:02
131. Palindrome Partitioning 刷题地址
https://leetcode.com/problems/palindrome-partitioning/#/description
AC
转载思路(dfs了半天没写明白)
http://blog.csdn.net/u012501459/article/details/46792453
重写的ac代码
class Solution {public: bool isPalindrome(string s, int sta, int en) { int i = sta; int j = en; while(i < j) { if(s[i] != s[j]) return false; i ++; j --; } return true; } void dfs(vector<vector<string>> &ans, vector<string> &v, string &s, int &slen, int index) { if(index == slen) // 表示处理完了整个string { ans.push_back(v); return; } // index位置之后的字符串,每个位置都可以分割 for(int i = index; i < slen; i++) { // 分割得到字符后,满足要求,再继续,直到最后无法对字符串分割 string tmp = s.substr(index, i - index + 1); if( isPalindrome(tmp, 0, (int)tmp.size() - 1) ) { v.push_back(tmp); // i之前的字符处理好了,接着递归处理i之后字符串 dfs(ans, v, s, slen, i + 1); v.pop_back(); } } } vector<vector<string>> partition(string s) { int len = s.size(); vector<vector<string>> ans; vector<string> v; dfs(ans, v, s, len, 0); return ans; }};
阅读全文
0 0
- 131. Palindrome Partitioning(字符串,dfs回溯)
- 131. Palindrome Partitioning回溯算法
- leetcode 131. Palindrome Partitioning-回溯算法
- LeetCode 131. Palindrome Partitioning--回溯法
- [LeetCode]--131. Palindrome Partitioning(backTracking && DFS && DP)
- 131 Palindrome Partitioning(dp+dfs)
- 【DFS】Palindrome Partitioning
- leetcode dfs Palindrome Partitioning
- Palindrome Partitioning DFS
- DFS Palindrome Partitioning
- LeetCode 131. Palindrome Partitioning 树形问题,状态回溯
- 字符串系列---palindrome-partitioning
- 131. Palindrome Partitioning(递归)
- leetcode -- Palindrome Partitioning -- 重点 dfs
- DFS——palindrome-partitioning
- LeetCode 131 Palindrome Partitioning (DFS)
- leetcode---palindrome-partitioning---dp, dfs
- leetcode 131. Palindrome Partitioning回文子串+DFS
- ios block探究及block野指针异常报错分析解决
- AOP的底层实现-CGLIB动态代理和JDK动态代理
- Tensorflow保存模型,恢复模型,使用训练好的模型进行预测和提取中间输出(特征)
- mplayer安装和移植
- 2017.05.25回顾 lift转roc 不会出现前期发力模型
- 131. Palindrome Partitioning(字符串,dfs回溯)
- sql server 死锁查询及解锁方法
- 输入一个字符串A,求其中最长的连续递增子串的长度。例如 "hidefef" 中最长的连续递增子串是 "def" ,长度为 3
- Unsupported major.minor version 52.0解决办法
- 连接MySql的时候报1130的错误解决办法
- Postman 发送请求
- 培养新人的一点感悟!
- pathon学习之—— os.path模块
- 《UNIX环境高级编程》第11章 线程