【leetcode】Palindrome Partitioning
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"]
]
class Solution {
public:
vector<vector <string> > res;
vector<vector<bool> > palindrome;
string s;
int n;
vector<vector<string>> partition(string s) {
this->s=s;
this->n=s.length();
vector<vector<bool> > palindrome(n,vector<bool>(n));
getPalindrome(palindrome);
this->palindrome=palindrome;
vector <string> tmp;
getPartition(,tmp);
return res;
}
//回溯得到子串
void getPartition(int start,vector<string> tmp)
{
if(start==n)
{
res.push_back(tmp);
return;
}
for(int i=start;i<n;i++)
{
if(palindrome[start][i])
{
tmp.push_back(s.substr(start,i-start+));
getPartition(i+,tmp);
tmp.pop_back();
}
}
}
void getPalindrome(vector<vector<bool> > &palindrome)
{
int startIndex=;
int endIndex=n-;
for(int i=n-;i>=;i--)
{
for(int j=i;j<n;j++)
{
if(i==j)
{
palindrome[i][j]=true;
}
else if(j-i==)
{
palindrome[i][j]=(s[i]==s[j]);
}
else if(j-i>)
{
palindrome[i][j]=(s[i]==s[j]&&palindrome[i+][j-]);
}
}
}
}
};
【leetcode】Palindrome Partitioning的更多相关文章
- 【LeetCode】Palindrome Partitioning 解题报告
[题目] Given a string s, partition s such that every substring of the partition is a palindrome. Retur ...
- 【leetcode】Palindrome Partitioning II(hard) ☆
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- 【leetcode】Palindrome Partitioning II
Palindrome Partitioning II Given a string s, partition s such that every substring of the partition ...
- 【Leetcode】【Medium】Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- 【leetcode】 Palindrome Partitioniong (middle) (*^__^*)
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- 【leetcode】Palindrome Number
题目简述: Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could n ...
- 【LeetCode】Palindrome Pairs(336)
1. Description Given a list of unique words. Find all pairs of distinct indices (i, j) in the given ...
- 【leetcode】Palindrome Number (easy)
Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negativ ...
- 【LeetCode】Palindrome Number(回文数)
这道题是LeetCode里的第9道题. 题目说的: 判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: ...
随机推荐
- Java基础-内部类
在Java中,可以将一个类定义在另一个类里面或者一个方法里面,这样的类称为内部类.广泛意义上的内部类一般来说包括这四种:成员内部类.局部内部类.匿名内部类和静态内部类. 下面就先来了解一下这四种内部类 ...
- sphinx在c#.net平台下使用(一)
Sphinx是由俄罗斯人Andrew Aksyonoff开发的一个可以结合MySQL,PostgreSQL全文检索引擎.意图为其他应用提供高速.低空间占用.高结果 相关度的全文搜索功能.是做站内全文搜 ...
- Codevs2157 配对
题目描述 Description 给出2个序列A={a[1],a[2],…,a[n]},B={b[1],b[2],…,b[n]},从A.B中各选出n个元素进行一一配对(可以不按照原来在序列中的顺序), ...
- Code Review Engine Learning
相关学习资料 https://www.owasp.org/index.php/Code_review https://www.owasp.org/images/8/8e/OWASP_Code_Revi ...
- openSSL命令、PKI、CA、SSL证书原理
相关学习资料 http://baike.baidu.com/view/7615.htm?fr=aladdin http://www.ibm.com/developerworks/cn/security ...
- web端测试和移动端测试的区别小记
转:http://qa.blog.163.com/blog/static/19014700220157128345318/ 之前一直参与web端的测试,最近一个项目加入了移动端,本人有幸参与了移动端的 ...
- 基础总结篇之三:Activity的task相关
http://blog.csdn.net/liuhe688/article/details/6761337 古人學問無遺力,少壯工夫老始成.紙上得來終覺淺,絕知此事要躬行.南宋.陸遊<冬夜讀書示 ...
- Java中各种(类、方法、属性)访问修饰符与修饰符的说明
类: 访问修饰符 修饰符 class 类名称 extends 父类名称 implement 接口名称 (访问修饰符与修饰符的位置可以互换) 访问修饰符 名称 说明 备注 public 可以被本项目的所 ...
- linux经典命令学习
本文介绍Linux系统的若干经典命令的常用方法. (一)grep 主要用于搜索文件内容,查看是否跟要求的pattern相匹配. 1.grep -l 'boss' * 显示所有包含boss ...
- PHP中is_numeric函数十六进制绕过0day
0×00 简介国内一部分CMS程序里面有用到过is_numberic函数,我们先看看这个函数的结构bool is_numeric ( mixed $var )如果 var 是数字和数字字符串则返回 T ...