leetcode——131——Palindrome Partitioning
来源:互联网 发布:淘宝店铺营销推广方式 编辑:程序博客网 时间:2024/06/14 06:50
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"] ]
class Solution {public:bool isPalindrome(string s, int begin, int end){while (begin <= end){if (s[begin] != s[end])return false;begin++;end--;}return true;}vector<vector<string>> partition(string s) {vector<vector<string> > res;int pos = 0;if (s.size() == 1) {vector<string> tmp;tmp.push_back(s);res.push_back(tmp);return res;}while (pos < s.size()) {if (isPalindrome(s, 0, pos)) {if (pos == s.size() - 1) {vector<string> tmp;tmp.push_back(s);res.push_back(tmp);}else {vector<vector<string> > subres = partition(s.substr(pos + 1));for (int k = 0; k < subres.size(); ++k) {subres[k].insert(subres[k].begin(), s.substr(0, pos + 1));res.push_back(subres[k]);}}}pos++;}return res;}};
0 0
- LeetCode——Palindrome Partitioning
- leetcode 131 —— Palindrome Partitioning
- LeetCode——Palindrome Partitioning II
- leetcode——Palindrome Partitioning II
- leetcode 132 —— Palindrome Partitioning II
- leetcode131—Palindrome Partitioning
- leetcode——131——Palindrome Partitioning
- LeetCode131——Palindrome Partitioning
- DFS——palindrome-partitioning
- Algorithms—131.Palindrome Partitioning
- leetcode——132—— Palindrome Partitioning II
- LeetCode: Palindrome Partitioning [131]
- LeetCode 131 Palindrome Partitioning
- LeetCode(131)Palindrome Partitioning
- [leetcode 131] Palindrome Partitioning
- [leetcode]131 Palindrome Partitioning
- LeetCode 131 Palindrome Partitioning
- leetcode ||131、Palindrome Partitioning
- leetcode 064 Minimum Path Sum
- 数据库的备份与还原(vb.net代码篇)
- STL——vector和map
- 自己对Handler的一些理解
- windows系统下自定义图标
- leetcode——131——Palindrome Partitioning
- HDU1242-Rescue
- java二维数组
- linux mysql配置
- 最小生成树-prime算法
- 陌上花开缓缓归
- HDU 1236 强连通分量
- hdu 3068 最长回文 Manacher算法
- HDU1045&&ZOJ1002-Fire Net