当前位置:网站首页>131.分割回文串
131.分割回文串
2022-07-30 05:38:00 【Linke66】


解题思路:
使用深度优先搜索,一旦搜索到回文字符串,那么就进入递归,并且递归中从上一次搜索的下一个位置开始搜索。具体见代码。
class Solution {
vector<vector<string>> ret;
public:
//判断是否是回文字符串
bool calc(const string& s){
int i=0,j=s.size()-1;
while(i<j){
if(s[i]!=s[j]) return false;
++i;
--j;
}
return true;
}
vector<vector<string>> partition(string s) {
vector<string> vec;
dfs(s,vec,0);
return ret;
}
void dfs(const string& s,vector<string>& vec,int start){
//假如能够递归到这一步说明字符串s已经分割完毕,且都是回文字符串
if(start>=s.size())
{
ret.push_back(vec);
return;
}
string tmp;
for(int i=start;i<s.size();++i){
tmp+=s[i];
//看是否是回文串,是的话进入递归
if(calc(tmp)){
vec.push_back(tmp);
dfs(s,vec,i+1);
vec.pop_back();
}
}
}
};
边栏推荐
- MySQL database basics (a systematic introduction)
- 解决没有配置本地nacos但是一直发生localhost8848连接异常的问题
- [GLib] 什么是GType
- Solve the problem that the local nacos is not configured but the localhost8848 connection exception always occurs
- Graphic mirror symmetry (schematic diagram)
- MySQL 数据库基础知识(系统化一篇入门)
- 最新版MySQL 8.0 的下载与安装(详细教程)
- 瑞吉外卖项目:新增菜品与菜品分页查询
- net start mysql MySQL service is starting. MySQL service failed to start.The service did not report any errors.
- cookie和session区别
猜你喜欢

Personal blog system (with source code)

How is crawler data collected and organized?
![[GO Language Basics] 1. Why do I want to learn Golang and the popularization of GO language entry](/img/ac/80ab67505f7df52d92a206bc3dd50e.png)
[GO Language Basics] 1. Why do I want to learn Golang and the popularization of GO language entry

cnpm安装步骤

navicat无法连接mysql超详细处理方法

Navicat cannot connect to mysql super detailed processing method

mysql time field is set to current time by default

2022 SQL big factory high-frequency practical interview questions (detailed analysis)
![[其他] DS5](/img/20/6863bb7b58d2e60b35469ba32e5830.png)
[其他] DS5

MySql模糊查询大全
随机推荐
cookie和session区别
MySQL stored procedure
Different usage scenarios of subqueries as retrieval tables and the question of whether to add aliases
Detailed MySQL-Explain
839. 模拟堆
It is enough for MySQL to have this article (37k words, just like Bojun!!!)
75. 颜色分类
Teach you how to design a CSDN system
Learn FPGA from the underlying structure (6) ---- Distributed RAM (DRAM, Distributed RAM)
[Other] DS5
What is SOA (Service Oriented Architecture)?
机器学习—梯度下降Gradient Descent Optimization—c语言实现
相对路径和绝对路径的区别
[GO Language Basics] 1. Why do I want to learn Golang and the popularization of GO language entry
倒计数(来源:Google Kickstart2020 Round C Problem A)(DAY 88)
net start mysql MySQL 服务正在启动 . MySQL 服务无法启动。 服务没有报告任何错误。
"Hou Lang" programmer version, a speech dedicated to a new generation of programmers, He Bing's "Hou Lang" speech imitation show
enumerate() 函数
MySql fuzzy query Daquan
Programmers make money and practice, teach you how to do paid courses, self-media, paid articles and paid technical courses to make money