题目链接

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. SpringBoot 集成mongodb(2)多数据源配置

    github:https://github.com/xiaozhuanfeng/mongoProj 现MongoDB有两个数据库: pom.xml: <!-- mongodb 配置 --> ...

  2. UDP 首部的格式

    <图解TCP/IP>6.6 UDP首部的格式 源端口号:表示发送端端口号,字段长16位.该字段是可选项,有时可能不会设置源端口号.没有源端口号的时候该字段的设置为0.可用于不需要返回的通信 ...

  3. 07 oracle 非归档模式 inactive/active/current redo log损坏的恢复

    在非归档模式下缺失Redo Log后的恢复 将之前的归档模式修改为非归档 SQL> shutdown immediate; SQL> startup mount SQL> alter ...

  4. 20191105 《Spring5高级编程》笔记-第9章

    第9章 事务管理 一些名词: 2PC(2 Phase Commit) XA协议 JTS(Java Transaction Service) JCA(Java EE Connector Architec ...

  5. 《深入浅出WPF》学习总结之XAML标签语言一

    一.XMAL概览 1.XAML在桌面开发及富媒体网络程序的开发中扮演了HTML+CSS+JS的角色. 2.XAML可以将UI和逻辑代码分离,降低耦合度. 3.XAML是一种单纯的申明形语言 4.XAM ...

  6. centos7下搭建Testlink环境详细过程

    花了半天的时间终于搭建好了完整的Testlink环境,主要包括Mysql以及PHP的版本.未关闭防火墙.以及安装配置过程中遇到的一些问题.以下是详细的搭建过程. 一.工具准备 以下是我在搭建过程中用到 ...

  7. Hadoop Map/Reduce

    Hadoop Map/Reduce是一个使用简易的软件框架,基于它写出来的应用程序能够运行在由上千个商用机器组成的大型集群上,并以一种可靠容错的方式并行处理上T级别的数据集.一个Map/Reduce ...

  8. 懵圈了,面试官问一个 TCP 连接可发多少个 HTTP 请求?

    作者:松若章 https://zhuanlan.zhihu.com/p/61423830 一道经典的面试题是从 URL 在浏览器被被输入到页面展现的过程中发生了什么,大多数回答都是说请求响应之后 DO ...

  9. Linux安装了mysql 无法远程连接

    问题: 本地安装完mysql,无法远程连接 1.检查mysql进程是否启动 ps -ef|grep -i mysql 2.查看端口是否监听 netstat -ntlp 3.查看iptables配置 v ...

  10. 所有的数据处理都是map-reduce

    用reduce求和 const sum = [1,2,3,4,5,6].reduce((v,t)=>{ return v+t; //第一次v=0,t=1 //第二次v= 0+1,t=2 //第三 ...