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;
}
};

最新文章

  1. mac个人设置
  2. 关于java连接mysql数据库的几个问题的解决方法。
  3. bugs
  4. Bitmap动画
  5. HBase体系结构剖析
  6. jq使用手册
  7. ExtJs3常用控件操作实例
  8. Linux学习——粘粘今天看的东西
  9. 换行符以及for循环的优化
  10. 强悍的跨平台开源多媒体中心XBMC介绍
  11. bzoj 1058: [ZJOI2007]报表统计
  12. js继承之组合继承(结合原型链继承 和 借用构造函数继承)
  13. http 响应状态码介绍
  14. H5的段落标签、图片标签、列表标签与链接标签
  15. JS变量的提升详解
  16. 剑指Offer 66. 机器人的运动范围 (回溯)
  17. 通过Java构造参数列表
  18. AES对数据进行加密与解密
  19. 在ubuntu中安装rpm包
  20. 前端jquery---表单验证

热门文章

  1. 企业级镜像仓库 harbor
  2. VS Code + WSL 搭建 RaspberryPi Pico 开发环境
  3. 安卓使用讯飞sdk报错
  4. Jmeter系列(1) - 踩坑之代理服务器录制失败
  5. P7597 「EZEC-8」猜树 加强版
  6. Spirit带你了解CSS各个方向的居中方案
  7. P4245-[模板]任意模数多项式乘法
  8. 02-token
  9. python-matplotlib学习(1)
  10. SphereEx 登陆 ApacheCon Asia|依托 ShardingSphere 可插拔架构体系打造数据应用完整生态