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的更多相关文章

  1. LeetCode_Palindrome Partitioning II

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

  2. [LeetCode] Palindrome Partitioning II 拆分回文串之二

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

  3. [LeetCode] Palindrome Partitioning 拆分回文串

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

  4. Leetcode: Palindrome Partitioning II

    参考:http://www.cppblog.com/wicbnu/archive/2013/03/18/198565.html 我太喜欢用dfs和回溯法了,但是这些暴力的方法加上剪枝之后复杂度依然是很 ...

  5. 測試大型資料表的 Horizontal Partitioning 水平切割

    FileGroup 檔案群組 :一個「資料庫(database)」可對應一或多個 FileGroup,一個 FileGroup 可由一或多個 file (.ndf) 構成. FileGroup 可讓 ...

  6. 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 ...

  7. LintCode Palindrome Partitioning II

    Given a string s, cut s into some substrings such that every substring is a palindrome. Return the m ...

  8. 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 ...

  9. 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- ...

随机推荐

  1. 关闭WIN10的UAC/自动更新/杀毒软件(兼容WIN7/8/8.1)

    第一部分:禁用wuauserv服务以及关闭UAC(保存为DW10UD.REG) Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYS ...

  2. 深入浅出Node.js (10) - 测试

    10.1 单元测试 10.1.1 单元测试的意义 10.1.2 单元测试介绍 10.1.3 工程化与自动化 10.1.4 小结 10.2 性能测试 10.2.1 基准测试 10.2.2 压力测试 10 ...

  3. CoreData Multiple Context性能分析-读书笔记

    From: http://floriankugler.com/blog/2013/4/29/concurrent-core-data-stack-performance-shootout  http: ...

  4. hdu4622-Reincarnation(后缀自动机)

    Problem Description Now you are back,and have a task to do:Given you a string s consist of lower-cas ...

  5. 看了一本书,说可以利用Hierarchy Viewer优化布局

    看了一本书,说可以利用Hierarchy Viewer优化布局,今以志之. 参考:http://www.cnblogs.com/Rocky_/archive/2011/11/04/2236243.ht ...

  6. XSS完全解决方案

    xss 为什么不能阻止用户输入不安全数据 比如用户想发一篇标题的文章 1+1>2吗? 为什么不在数据库存的时候就处理好或者接口里处理好 1<2 会被转义为 1<2,放到html中确实 ...

  7. STM32F051 IAP源代码分享

    STM32F051 IAP源代码分享 假设不懂IAP的请自己主动脑补或者怒戳这里 http://www.openedv.com/posts/list/11494.htm 然后STM32F051的IAP ...

  8. [RxJS] Logging a Stream with do()

    To help understand your stream, you’ll almost always want to log out some the intermediate values to ...

  9. java实验7-多线程编程

    1 利用Thread和Runnable创建线程 [实验目的] (1)理解用实现Runnable接口的方法实现多线程. (2)掌握线程优先级的设置. (3)加深对线程状态转换的理解. [实验要求] 要求 ...

  10. Unity 对象池的使用

    在游戏开发过程中,我们经常会遇到游戏发布后,测试时玩着玩着明显的感觉到有卡顿现象.出现这种现象的有两个原因:一是游戏优化的不够好或者游戏逻辑本身设计的就有问题,二是手机硬件不行.好吧,对于作为程序员的 ...