LeetCode_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:
bool isPalindrome(const string &s, int start, int end)
{
assert(start< len && end < len) ;
if(start > end) return false ;
while(start < end)
{
if(s[start] != s[end])
return false;
start++;
end --;
}
return true;
}
void DFS(const string &s,int start, vector<string> p)
{
if(start == len) {
result.push_back(p);
return ;
}
for(int i = start; i< len ; i++)
{
if(isPalindrome(s,start, i))
{
p.push_back(s.substr(start, i - start +));
DFS(s, i+, p);
p.pop_back();
}
}
}
vector<vector<string>> partition(string s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
result.clear();
len = s.size();
if(len == ) return result;
vector<string> p;
DFS(s, , p);
return result ;
}
private:
int len ;
vector<vector<string>> result;
};
LeetCode_Palindrome Partitioning的更多相关文章
- LeetCode_Palindrome Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- [LeetCode] Palindrome Partitioning II 拆分回文串之二
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- [LeetCode] Palindrome Partitioning 拆分回文串
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- Leetcode: Palindrome Partitioning II
参考:http://www.cppblog.com/wicbnu/archive/2013/03/18/198565.html 我太喜欢用dfs和回溯法了,但是这些暴力的方法加上剪枝之后复杂度依然是很 ...
- 測試大型資料表的 Horizontal Partitioning 水平切割
FileGroup 檔案群組 :一個「資料庫(database)」可對應一或多個 FileGroup,一個 FileGroup 可由一或多個 file (.ndf) 構成. FileGroup 可讓 ...
- UVA - 11584 Partitioning by Palindromes[序列DP]
UVA - 11584 Partitioning by Palindromes We say a sequence of char- acters is a palindrome if it is t ...
- LintCode Palindrome Partitioning II
Given a string s, cut s into some substrings such that every substring is a palindrome. Return the m ...
- How to Remove Table Partitioning in SQL Server
In this article we will see how we can remove partitions from a table in a database in SQL server. I ...
- Partitioning & Archiving tables in SQL Server (Part 2: Split, Merge and Switch partitions)
Reference: http://blogs.msdn.com/b/felixmar/archive/2011/08/29/partitioning-amp-archiving-tables-in- ...
随机推荐
- TestNG基本注解(注释)
传统的方式来表示JUnit3中的测试方法是测试自己的名字前缀.标记一个类中的某些方法,具有特殊的意义,这是一个非常有效的方法,但命名不很好的扩展(如果我们想添加更多标签为不同的框架?),而非缺乏灵活性 ...
- mysql sql优化<1>
<pre name="code" class="html">explain SELECT t.* FROM ( SELECT t1.sn AS cl ...
- js深入研究之函数内的函数
第一种 function foo() { ; function bar() { a *= ; } bar(); return a; } 第二种 function foo() { ; function ...
- 【转】Win7系统下安装Ubuntu12.04(EasyBCD硬盘安装)--不错
原文网址:http://blog.csdn.net/lengbuleng1107/article/details/14532177 需要的东西有: 1,ubuntu系统镜像,下载地址:http://w ...
- Python闭包与函数对象
1. Python闭包是什么 在python中有函数闭包的概念,这个概念是什么意思呢,查看Wikipedia的说明如下: “ In programming languages, closures (a ...
- Unity性能优化
一.优化组件访问方式 原文:http://blog.csdn.net/lijing_hi/article/details/11657887 1.缓存Component的引用,如transform 2. ...
- sicily 1007 To and Fro
题意:字符串的操作处理 // Problem#: 8768 // Submission#: 2606406 // The source code is licensed under Creative ...
- Android HOME纽带,BACK主要采集和响应
1.onUserLeaveHint 相比Home键(HOME)而近期应用的关键(APP_SWITCH)治,回车键很简单.复onKeyDown可以实现,如以下: @Override public boo ...
- CentOS7--DNS处理模块DnsPython的简单使用
初步了解: DnsPython是Python实现的一个DNS工具包,支持几乎所有的记录类型. 安装: # wget http://www.dnspython.org/kits/1.9.4/dnspyt ...
- CentOS 6.5 伪分布式 安装 hadoop 2.6.0
安装 jdk -openjdk* 检查安装:java -version 创建Hadoop用户,设置Hadoop用户使之可以免密码ssh到localhost su - hadoop ssh-keygen ...