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 ...
随机推荐
- centos7防火墙的简单配置介绍
centos7版本 1.查看已开放的端口(默认不开放任何端口) firewall-cmd --list-ports 2.开启80端口 firewall-cmd --zone=public(作用域) - ...
- jstl c:choose>、<c:when>和<c:otherwise>标签的简单使用介绍
<c:choose>.<c:when>和<c:otherwise>在一起连用,可以实现Java语言中的if-else语句的功能.例如以下代码根据username请求 ...
- tomcat服务无响应堆栈分析
tomcat服务突然无响应了,导出内存堆栈和线程堆栈,分析后发现是同步锁使用不合理导致的. [root@prd-dtb-web-01 ~]# [root@prd-dtb-web-01 ~]# jmap ...
- list元素排序需要满足两个条件
关于List 说到list,我的印象就是单值集合接口,插入取出是有序的,允许重复,用他的实现类用的最频繁的就是ArrayList了.如果我现在有一个list,插入了一些值,想让里面的值按照我自定义的规 ...
- [CF1051F]The Shortest Statement
题目大意:给定一张$n$个点$m$条有权边的无向联通图,$q$次询问两点间的最短路 $n\le100000$,$m\le100000$,$1\le100000$,$m$-$n\le20$. 首先看到$ ...
- 防止xss(脚本攻击)的方法之过滤器
一 什么是脚本注入 概念我就不说了 直接百度一份 XSS是一种经常出现在web应用中的计算机安全漏洞,它允许恶意web用户将代码植入到提供给其它用户使用的页面中.比如这些代码包括HTML代码和客户端 ...
- brpc编译运行
自百度开源brpc后就一直在关注,看了下brpc都源码,感觉大牛写的果然不一样,由于之前我做c++游戏服务器开发,所以主要看了下网络底层代码,收益颇多,果然一天不学习就要落伍. 现在主要和大家说下我编 ...
- mysql创建数据库和用户
create database sonar character set utf8 collate utf8_general_ci; flush privileges; grant all privil ...
- Css(样式)
CSS三种样式 1.行内样式 ①将css样式与html,完全糅杂在一起,不符合w3c关于“内容与表现分离”的基本规范,不利于后期维护. ②优先级最高. 2.内部样式表 ...
- webservice的cxf的客户端
1.新建一个java项目 2.用cmd命令生成客户端的使用说明文档 wsdl2java -p xiaostudy -d . http://127.0.0.1:9998/number?wsdl 3.导入 ...