131. Palindrome Partitioning
来源:互联网 发布:mac管理桌面图标 编辑:程序博客网 时间:2024/06/05 13:36
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”]
]
思路:此题第一思路就是回溯,然后就是回溯算法的固定思路解此类问题了。
bool isSubPailndrome(string& str, int low, int high){ if (low == high)return true; while (low <= high){ if (str[low] == str[high])low++, high--; else return false; } return true;}void dfs_partition(string& s, int start, int end, vector<string>& path, vector<vector<string>>& res){ if (end == s.size()){ if (isSubPailndrome(s, start,end - 1)){ path.push_back(s.substr(start, end - start)); res.push_back(path); path.pop_back(); } return; } if (isSubPailndrome(s,start,end - 1)){ path.push_back(s.substr(start, end - start)); dfs_partition(s, end, end + 1, path, res); path.pop_back(); } dfs_partition(s, start, end + 1, path, res);}vector<vector<string>> partition(string s) { vector<vector<string>> res; if (s == "")return res; vector<string> path; dfs_partition(s, 0, 1, path, res); return res;}
阅读全文
0 0
- 131. Palindrome Partitioning && 132. Palindrome Partitioning II
- LeetCode 131. Palindrome Partitioning
- [LeetCode]131.Palindrome Partitioning
- [Leetcode] 131. Palindrome Partitioning
- [leetcode] 131.Palindrome Partitioning
- 131. Palindrome Partitioning
- 131. Palindrome Partitioning
- 131. Palindrome Partitioning
- [LeetCode]131. Palindrome Partitioning
- 131. Palindrome Partitioning LeetCode
- 131. Palindrome Partitioning
- Leetcode 131. Palindrome Partitioning
- 131. Palindrome Partitioning
- 131. Palindrome Partitioning
- LeetCode 131. Palindrome Partitioning
- LeetCode *** 131. Palindrome Partitioning
- 131. Palindrome Partitioning
- LeetCode 131. Palindrome Partitioning
- 九大排序
- PHP中的排序函数sort、asort、rsort、krsort、ksort区别分析
- 268. Missing Number
- bzoj3309 DZY Loves Math
- 服务响应对象设计
- 131. Palindrome Partitioning
- 劳工部起诉谷歌薪资信息,谷歌嫌收集证据成本贵
- linux 制作U盘启动,和定制系统
- C++抽象类
- http://dl-ssl.google.com/android上不去解决方案
- 你是不是 可替代的Linux运维工程师?
- Day 11 常用正则表达式
- 谨慎使用输出重定向(>)
- 最新版VMare安装Ubuntu和fedora失败问题