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 ...
随机推荐
- Selenium+Python常见定位方法
参见官网:http://selenium-python.readthedocs.io/locating-elements.html 有多种策略来定位页面中的元素.你可以使用最适合你的情况.Seleni ...
- java中数组以及集合
java中数组: 数组在Java里是一种特殊类型,有别于普通的“类的实例”的对象.但实际数组也是一种对象类型,int[]a = new int[5] a是在java栈中分配的引用变量,类型是int[ ...
- matlab基本操作总结
1.clear;//清除工作平台变量2.close all;//关闭打开的图形窗口3.I = imread('C:\Users\dell\Desktop\rice.jpg');//读取图像,存储在I数 ...
- CSS Link(链接)
CSS Link(链接) 不同的链接可以有不同的样式. 一.链接样式 链接的样式,可以用任何CSS属性(如颜色,字体,背景等). 特别的链接,可以有不同的样式,这取决于他们是什么状态. 这四个链接状态 ...
- 关于Log4Net的使用和配置
1. 添加log4net.dll引用 2.在添加引用的那层的 AssemblyInfo.cs 注册 : [assembly: log4net.Config.XmlConfigura ...
- hadoop namenode HA集群搭建
hadoop集群搭建(namenode是单点的) http://www.cnblogs.com/kisf/p/7456290.html HA集群需要zk, zk搭建:http://www.cnblo ...
- sqlx基础语法与应用
基础: ``` 引用:_ "github.com/go-sql-driver/mysql" "github.com/jmoiron/sqlx" ``` 初始化 ...
- JAVA基本常识及环境搭建
JAVA基本常识及环境搭建 常用dos命令行 dir 列出当前目录下的文件以及文件夹 md 创建目录 cd 进入指定目录 cd.. 退回到上一级目录 cd/ 退回到根目录 del 删除文件 删除单个文 ...
- js事件委托篇(附js一般写法和js、jq事件委托写法)
参考: jQuery代码优化:事件委托篇 使用该技术能让你避免对特定的每个节点添加事件监听器:相反,事件监听器被添加在他们的父元素上,事件监听器会分析从子元素上冒泡上来的事件,并找到是哪个子元素事件. ...
- cygwin下烧写文件到sd卡中
在cygwin下将firmware_sdcard.bin写入到sd卡中(cygwin需要以管理员身份启动) 1查看sd分区情况 cat /proc/partitions (为了找到sd卡的标记) 2 ...