LeetCode OJ:Palindrome Partitioning(回文排列)
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(回文排列)的更多相关文章
- [LeetCode] 131. Palindrome Partitioning 回文分割
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- [LeetCode] Valid Palindrome 验证回文字符串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- LeetCode Valid Palindrome 有效回文(字符串)
class Solution { public: bool isPalindrome(string s) { if(s=="") return true; ) return tru ...
- [LeetCode] Shortest Palindrome 最短回文串
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...
- [LeetCode] Prime Palindrome 质数回文数
Find the smallest prime palindrome greater than or equal to N. Recall that a number is prime if it's ...
- 131. Palindrome Partitioning(回文子串划分 深度优先)
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- leetcode 9 Palindrome Number 回文数
Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...
- [LeetCode] 266. Palindrome Permutation 回文全排列
Given a string, determine if a permutation of the string could form a palindrome. Example 1: Input: ...
- Leetcode 3——Palindrome Number(回文数)
Problem: Determine whether an integer is a palindrome. Do this without extra space. 简单的回文数,大一肯定有要求写过 ...
- [Leetcode] valid palindrome 验证回文
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
随机推荐
- 保持简单----纪念丹尼斯•里奇(Dennis Ritchie)
http://www.ruanyifeng.com/blog/2011/10/dennis_ritchie.html
- NIO 03
1. 客户端要主动去连接:channel.connect(new InetSocketAddress("localhost",8888)); //用channel.finishCo ...
- Ubuntu 14.04.5 imx6 开发环境搭建
1,下载VMware Workstation虚拟机 地址:http://1.xp510.com:801/xp2011/VMware10.7z 2,下载Ubuntu 14.04.5 LTS 32位Ubu ...
- JavaScript常用算法
一.排序算法 1.Array.sort(function)(JavaScript原生排序算法)参数:比较函数(可选)若无参数,则按照首字母的ASCII码排序,比较函数的作用为确定排序 function ...
- spring cloud要点简介及常用组件
spring cloud基于spring boot spring cloud是通过包装其他技术框架实现的,例如OSS组件,实现了一套通过基于注解.java配置和基于模板开发的微服务框架. spring ...
- 20135302魏静静——linux课程第四周实验及总结
linux课程第四周实验及总结 一.实验 我选择的是第20号系统调用,getpid 代码如下: /* getpid.c */ #include <unistd.h> #include &l ...
- mongodb入门很简单(2)
mongodb的安装 1.下载mongodb: www.mongodb.org 下载最新的stable版:我下载的版本是3.2.5 2.解压文件 3.不用编译:本身就是编译后的二进制可执行文件 打开 ...
- C#开发自己的Web服务器
介绍 我们将学习如何写一个简单的web服务器,用于响应知名的HTTP请求(GET和POST),用C#发送响应.然后,我们从网络访问这台服务器,这次我们会说“Hello world!” 背景 HTTP协 ...
- Spring Container的扩展点
转自: http://blog.csdn.net/kkdelta/article/details/5488430 Spring在解析完配置文件后,会调用一些callback方法,使用Spring的开发 ...
- 【Semantic Segmentation】Segmentation综述
部分转自:https://zhuanlan.zhihu.com/p/37618829 一.语义分割基本介绍 1.1 概念 语义分割(semantic segmentation) : 就是按照" ...