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. JavaEE学习记录(一)--软件系统体系结构

    1 常见软件系统体系结构B/S.C/S 1.1 C/S l C/S结构即客户端/服务器(Client/Server),例如QQ: l 需要编写服务器端程序,以及客户端程序,例如我们安装的就是QQ的客户 ...

  2. HCNP学习笔记之PXE原理详解及实践

    一.PXE简介 PXE(preboot execute environment,预启动执行环境)是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持工作站通过网络从远端服 ...

  3. Python3.x:定义一个类并且调用

    Python3.x:定义一个类并且调用 1,定一个类Shrjj(其中有属性:name, jjzt,fbsjj,etf,lof,fjlof): class Shrjj(object): def __in ...

  4. 20145302张薇 Java第一周学习总结

    20145302张薇 <Java程序设计>第一周学习总结 教材学习内容总结 第一章 1995年,java被公认诞生.java第一开始为了消费性数字产品(如手机)而设计,所以java本身有很 ...

  5. 20145307第八周JAVA学习报告

    20145307<Java程序设计>第8周学习总结 教材学习内容总结 通用API 日志API 1.java.util.logging包提供了日志功能相关类与接口,使用日志的起点是logge ...

  6. 20145314郑凯杰 《Java程序设计》第8周学习总结

    20145314郑凯杰 <Java程序设计>第8周学习总结 教材学习内容总结 代码已托管 第十五章 通用API ①日志: 日志对信息安全意义重大,审计.取证.入侵检测等都会用到日志信息 使 ...

  7. oracle update set select from 关联更新

    工作中有个需求,现在新表中有一些数据跟老表的基本一样,这样只需要把老表中数据搬到新表中就可以了,同时把不同的字段修改下数据即可,在修改字段时发现,需要指定一个条件,比如主键id,来修改某条记录,这样一 ...

  8. bzoj 3545: [ONTAK2010]Peaks

    Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1124  Solved: 304[Submit][Status][Discuss] Descripti ...

  9. wechat4j获取用户昵称乱码修复

    项目对接微信公众号平台时,微信的官方给出的建议是使用wechat4j.官方建议的,自然心里踏实,但实际用起来时发现wechat4j埋有很多雷,最让人心烦意乱的就是中文乱码问题. 之前写过一篇为JAXB ...

  10. Linux升级内核总结

    Linux内核升级总结. 一.编译内核步骤 1.#uname –r 确定系统的原内核版本,然后下载较新版本的Linux内核源码包 http://www.kernel.org/pub/linux/ker ...