Leetcode Palindrome Partitioning
来源:互联网 发布:手机淘宝怎么申请试用 编辑:程序博客网 时间:2024/05/20 23:32
题意:找到字符串中所有的回文。
思路:DFS,暴力搜索。
class Solution {public: vector<vector<string>> re; vector<vector<string>> partition(string s) { vector<string> ss; dfs(ss, s); return re; } bool isP(string s) { for(int i = 0; i < s.length() / 2; ++ i) { if(s[i] != s[s.length() - i - 1]) return false; } return true; } void dfs(vector<string> rre, string s) {// cout << s << endl; if(s.length() == 0) { re.push_back(rre); return; } string s1; for(int i = 0; i < s.length(); ++ i) { s1 = s.substr(0, i + 1); //cout << i << endl; //cout << s.substr(i + 1, s.length() - i - 1) << endl; if(isP(s1)) { vector<string> temp = rre; temp.push_back(s1); //for(int j = 0; j < rre.size(); j ++) cout << rre[j] << endl; cout << endl; dfs(temp, s.substr(i + 1, s.length() - i - 1)); } } return; }};
此题还有DP的方法,值的思考。
0 0
- 【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
- [Leetcode][python]Palindrome Partitioning/Palindrome Partitioning II
- Leetcode:Palindrome Partitioning & Palindrome Partitioning II
- LeetCode: Palindrome Partitioning
- LeetCode : Palindrome Partitioning II
- [leetcode] Palindrome Partitioning II
- leetcode 122: Palindrome Partitioning
- leetcode:Palindrome Partitioning II
- leetcode:Palindrome Partitioning
- 【leetcode】Palindrome Partitioning
- 【leetcode】Palindrome Partitioning II
- leetcode - Palindrome Partitioning II
- Leetcode - Palindrome Partitioning
- LeetCode之Palindrome Partitioning
- [LeetCode]Palindrome Partitioning
- 发布几个 比较好用的小说网站
- [仿南航app开发日记4]登陆对话框完成以及自定义对话框碰到的坑
- NOIP 提高组 初赛 四、阅读程序写结果 习题集(六)NOIP2008-NOIP2009
- 第2章 对象及变量的并发访问
- C# 集合
- Leetcode Palindrome Partitioning
- docker常用命令(一)
- (转)HTML table、form表单标签的介绍
- 理念高大上的智慧社区,要落地还得俯下身解决四个现实问题
- 看这里!2017年第一弹-Java学习资源大放送!
- owasp-zap设置扫描策略
- ffmpeg RTMP【转】
- 欢迎使用CSDN-markdown编辑器
- 14. Longest Common Prefix