palindrome-partitioning leetcode C++
2024-08-31 02:52:35
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"] ]
C++
class Solution {
public:
vector<vector<string>> partition(string s){
vector<vector<string>> res;
vector<string> out;
partitionDFS(s,0,out,res);
return res;
}
void partitionDFS(string s, int start, vector<string> &out, vector<vector<string>> &res) {
if (start == s.size()) {
res.push_back(out);
return;
}
for (int i = start; i < s.size(); ++i) {
if (isPalindrome(s, start, i)) {
out.push_back(s.substr(start, i - start + 1));
partitionDFS(s, i + 1, out, res);
out.pop_back();
}
}
}
bool isPalindrome(string s, int start, int end) {
while (start < end) {
if (s[start] != s[end]) return false;
++start;
--end;
}
return true;
}
};
最新文章
- mac个人设置
- 关于java连接mysql数据库的几个问题的解决方法。
- bugs
- Bitmap动画
- HBase体系结构剖析
- jq使用手册
- ExtJs3常用控件操作实例
- Linux学习——粘粘今天看的东西
- 换行符以及for循环的优化
- 强悍的跨平台开源多媒体中心XBMC介绍
- bzoj 1058: [ZJOI2007]报表统计
- js继承之组合继承(结合原型链继承 和 借用构造函数继承)
- http 响应状态码介绍
- H5的段落标签、图片标签、列表标签与链接标签
- JS变量的提升详解
- 剑指Offer 66. 机器人的运动范围 (回溯)
- 通过Java构造参数列表
- AES对数据进行加密与解密
- 在ubuntu中安装rpm包
- 前端jquery---表单验证