题目链接

Given a string s, partition s such that every substring of the partition is a palindrome.

Return all possible palindrome partitioning of s.

Example:

Input: "aab"
Output:
[
["aa","b"],
["a","a","b"]
] 题意简单明了。
解法:要找到所有的划分方法,应想到穷举。
class Solution {
public:
bool isPalindrome(string s){
for(size_t i=; i<s.size()/; i++)
if(s[i] != s[s.size()--i])
return false;
return true;
} vector<vector<string>> partition(string s) {
vector<vector<string>> ret;
vector<string> temp;
dfs(s, , temp, ret);
return ret;
} void dfs(string& s, int idx, vector<string>& temp, vector<vector<string>>& ret){
if(idx == s.size()){
ret.push_back(temp);
return;
}
for(size_t i=; i<=s.size()-idx; i++){
string prefix = s.substr(idx, i);
if(isPalindrome(prefix)){
temp.push_back(prefix);
dfs(s, idx+i, temp, ret);
temp.pop_back();
}
}
}
};

Leetcode_131. Palindrome Partitioning_[DFS]的更多相关文章

  1. leetcode_目录

    3Sum Closest 3Sum 4Sum Add Binary Add Two Numbers Anagrams Balanced Binary Tree Best Time to Buy and ...

  2. leetcode dfs Palindrome Partitioning

    Palindrome Partitioning Total Accepted: 21056 Total Submissions: 81036My Submissions Given a string  ...

  3. 2019牛客暑期多校训练营(第六场)Palindrome Mouse 回文树+dfs

    题目传送门 题意:给出一个字符串,将字符串中所有的回文子串全部放入一个集合里,去重后.问这个集合里有几对<a,b>,使得a是b的子串. 思路:一开始想偏了,以为只要求每个回文串的回文后缀的 ...

  4. 2019牛客暑期多校训练营(第六场)C Palindrome Mouse (回文树+DFS)

    题目传送门 题意 给一个字符串s,然后将s中所有本质不同回文子串放到一个集合S里面,问S中的两个元素\(a,b\)满足\(a\)是\(b\)的子串的个数. 分析 首先要会回文树(回文自动机,一种有限状 ...

  5. [LeetCode] Palindrome Partitioning 拆分回文串

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

  6. Leetcode: Palindrome Partitioning II

    参考:http://www.cppblog.com/wicbnu/archive/2013/03/18/198565.html 我太喜欢用dfs和回溯法了,但是这些暴力的方法加上剪枝之后复杂度依然是很 ...

  7. Leetcode 131. Palindrome Partitioning

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

  8. [Leetcode] Palindrome Partitioning

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

  9. LeetCode Palindrome Permutation II

    原题链接在这里:https://leetcode.com/problems/palindrome-permutation-ii/ 题目: Given a string s, return all th ...

随机推荐

  1. DirectX 安装报错: 不能信任一个安装所需的压缩文件,请检查加密服务是否启用并且cabinet文件证书是否有效

    DirectX 安装报错 不能信任一个安装所需的压缩文件,请检查加密服务是否启用并且cabinet文件证书是否有效 是直播软件open broadcaster software,这个软件安装的时候提示 ...

  2. 【ABAP系列】SAP ABAP 用BAPI批量导入物料的质量视图

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP ABAP 用BAPI批量导入 ...

  3. python基础-9__import__ 反射和面向对象基础 self 封装 继承(多继承顺序) 多态

    一 反射 python中的反射功能是由以下四个内置函数提供:hasattr.getattr.setattr.delattr,改四个函数分别用于对对象内部执行:检查是否含有某成员.获取成员.设置成员.删 ...

  4. web 前端2 CSS

    CSS CSS是Cascading Style Sheets的简称,中文称为层叠样式表,用来控制网页数据的表现,可以使网页的表现与数据内容分离. 一 css的四种引入方式 1.行内式          ...

  5. Windows 10更新后无法启动Dolby音频驱动程序

    在电脑更新Windows 10 1903版本后,重启出现如下问题: 经查,这与驱动强制签名有关.解决方法如下: 打开"设置"->"更新与安全"->& ...

  6. spring-第十五篇之AOP面向切面编程之AspectJ框架简单应用

    1.去官方网站下载aspectj-1.8.0.jar 2.在jar包目录启动cmd,执行java -jar aspectj-1.8.0.jar,Next 3.检查JAVA_HOME路径是否正确,如果不 ...

  7. 回溯---Permutations II

    47.Permutations II (Medium)](https://leetcode.com/problems/permutations-ii/description/) [1,1,2] hav ...

  8. Django:django-debug-toolbar模块

    简介: Django的django-debug-toolbar 模块是一组可配置的面板,可显示有关当前请求/响应的各种调试信息,并在单击时显示有关面板内容的更多详细信息. GitHub源文件下载地址 ...

  9. nginx入门(一)

    什么是nginx? nginx是一款高性能的http 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器.由俄罗斯的程序设计师Igor Sysoev所开发,官方测试nginx能够支支撑5 ...

  10. jQ:"对象不支持“first”属性或方法"IE内核下不兼容first()、chilrdren()方法的处理

    场景:需要查找某元素下的第一个子集,使用了如下语句: $("#left_1>tbody").find(".menuTr").first().addClas ...