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"]
]

典型的dfs,代码如下:

 class Solution {
public:
vector<vector<string>> partition(string s) {
vector<string> path;
dfs(s, path);
return ret;
} void dfs(string s, vector<string> & path)
{
if(s.size() < )
ret.push_back(path);
for(int i = ; i < s.size(); ++i){
int start = ;
int end = i;
while(start < end){
if(s[start] == s[end])
start++, end--;
else
break;
}
if(start >= end){
path.push_back(s.substr(,i+));
dfs(s.substr(i+), path);
path.pop_back();
}
}
} private:
vector<vector<string>> ret; };

LeetCode OJ:Palindrome Partitioning(回文排列)的更多相关文章

  1. [LeetCode] 131. Palindrome Partitioning 回文分割

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

  2. [LeetCode] Valid Palindrome 验证回文字符串

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  3. LeetCode Valid Palindrome 有效回文(字符串)

    class Solution { public: bool isPalindrome(string s) { if(s=="") return true; ) return tru ...

  4. [LeetCode] Shortest Palindrome 最短回文串

    Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...

  5. [LeetCode] Prime Palindrome 质数回文数

    Find the smallest prime palindrome greater than or equal to N. Recall that a number is prime if it's ...

  6. 131. Palindrome Partitioning(回文子串划分 深度优先)

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

  7. leetcode 9 Palindrome Number 回文数

    Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...

  8. [LeetCode] 266. Palindrome Permutation 回文全排列

    Given a string, determine if a permutation of the string could form a palindrome. Example 1: Input: ...

  9. Leetcode 3——Palindrome Number(回文数)

    Problem: Determine whether an integer is a palindrome. Do this without extra space. 简单的回文数,大一肯定有要求写过 ...

  10. [Leetcode] valid palindrome 验证回文

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

随机推荐

  1. HTML DOM setInterval() 方法

    定义和用法 setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式. setInterval() 方法会不停地调用函数,直到 clearInterval() 被调用或窗口被 ...

  2. c调用c++编的dll,c++调用c编写的dll,extern “C”的用法

    转自:http://blog.csdn.net/life_is_too_hard/article/details/52137271 c和c++不能直接相互调用,主要是因为c++有重载函数的功能,为了区 ...

  3. CSS3 简介

    CSS3 简介 对CSS3已完全向后兼容,所以你就不必改变现有的设计.浏览器将永远支持CSS2. CSS3被拆分为"模块".旧规范已拆分成小块,还增加了新的. 一些最重要CSS3模 ...

  4. goland 使用简单配置-不断更新

    1.格式化代码 Ctrl+Alt+L  格式化代码 2.快捷键可能被占用 用tools-file watchers file->setting->tools->file watche ...

  5. 20145301《Java程序设计》实验报告一:Java开发环境的熟悉

    20145301<Java程序设计>实验报告一:Java开发环境的熟悉 课程:Java程序设计 实验名称:Java开发环境的熟悉 实验目的与要求: 1.没有Linux基础的同学建议先学习& ...

  6. VMware 共享目录不显示的解决办法

    centos mount -t vmhgfs .host:/ /mnt/hgfs # 如果有如下提示: # Error: cannot mount filesystem: No such device ...

  7. Centos下ftp协议连接远程ftp server主机

    环境说明 [root@Check3 ~]# cat /etc/redhat-release CentOS release 6.9 (Final) [root@Check3 ~]# uname -a L ...

  8. git分支合并脚本

    为什么要写这个脚本 工作中经常会有合并分支的操作,一开始也不以为然,后来发现如果更新频繁的话,根本就停不下来,昨天上午正好有空,就完成了下面的这个初版 可能存在的问题 一般的应用场景都是:从maste ...

  9. [HAOI2015]T2

    [题目描述] 有一棵点数为N的树,以点1为根,且树点有边权.然后有M个操作,分为三种: 操作1:把某个节点x的点权增加a. 操作2:把某个节点x为根的子树中所有点的点权都增加a. 操作3:询问某个节点 ...

  10. PayPal2019春招实习生笔试题的某一题

    题目简单描述:给你n个点的坐标(x, y),均为浮点数. 如果任意两个点之间的欧几里得距离小于给定的一个浮点值,则认为这两个点之间有关联,并且关联具有传递性,总之就是尽可能扩大一个集合. 输入: d ...