给定一个字符串 s,将 s 分割成一些子串,使每个子串都是回文串。

返回 s 所有可能的分割方案。

示例:

输入: "aab" 输出: [ ["aa","b"], ["a","a","b"] ]

class Solution {
public:
vector<vector<string> >res;
int len;
vector<vector<string> > partition(string s)
{
len = s.size();
if(len == 0)
return res;
vector<string> v;
DFS(v, s, 0);
return res;
} void DFS(vector<string> &v, string str, int pos)
{
if(pos >= len)
{
res.push_back(v);
}
for(int i = pos; i < len; i++)
{
int flag = true;
for(int j = 0; j <= (i - pos + 1) / 2; j++)
{
if(str[pos + j] != str[i - j])
{
flag = false;
break;
}
}
if(!flag)
continue;
v.push_back(string(str.begin() + pos, str.begin() + i + 1));
DFS(v, str, i + 1);
v.pop_back();
}
}
};

Leetcode131. Palindrome Partitioning分割回文串的更多相关文章

  1. lintcode:Palindrome Partitioning 分割回文串

    题目: 分割回文串 给定一个字符串s,将s分割成一些子串,使每个子串都是回文串. 返回s所有可能的回文串分割方案. 样例 给出 s = "aab",返回 [ ["aa&q ...

  2. 131 Palindrome Partitioning 分割回文串

    给定一个字符串 s,将 s 分割成一些子串,使每个子串都是回文串.返回 s 所有可能的分割方案.例如,给出 s = "aab",返回[  ["aa"," ...

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

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

  4. LeetCode 131. 分割回文串(Palindrome Partitioning)

    131. 分割回文串 131. Palindrome Partitioning 题目描述 给定一个字符串 s,将 s 分割成一些子串,使每个子串都是回文串. 返回 s 所有可能的分割方案. LeetC ...

  5. 分割回文串 · Palindrome Partitioning

    [抄题]: 给定一个字符串s,将s分割成一些子串,使每个子串都是回文串. 返回s所有可能的回文串分割方案. 给出 s = "aab",返回 [ ["aa", & ...

  6. Leetcode之回溯法专题-131. 分割回文串(Palindrome Partitioning)

    Leetcode之回溯法专题-131. 分割回文串(Palindrome Partitioning) 给定一个字符串 s,将 s 分割成一些子串,使每个子串都是回文串. 返回 s 所有可能的分割方案. ...

  7. Leetcode 132.分割回文串II

    分割回文串 给定一个字符串 s,将 s 分割成一些子串,使每个子串都是回文串. 返回符合要求的最少分割次数. 示例: 输入: "aab" 输出: 1 解释: 进行一次分割就可将 s ...

  8. Leetcode 131.分割回文串

    分割回文串 给定一个字符串 s,将 s 分割成一些子串,使每个子串都是回文串. 返回 s 所有可能的分割方案. 示例: 输入: "aab" 输出: [ ["aa" ...

  9. 【LEETCODE】72、分割回文串 III 第1278题

    package y2019.Algorithm.dynamicprogramming.hard; /** * @Auther: xiaof * @Date: 2019/12/11 08:59 * @D ...

随机推荐

  1. POJ 1127 /// 判断线段与线段是否相交

    题目大意: 给定n条线段 接下来n行是端点信息 接下来询问 a b 是否相交 若a与c相交 b与c相交 ,那么a与b就是相交的 先判断任两条线段是否相交 再用folyd #include <cs ...

  2. 分布式日志收集之Logstash 笔记(一)

    (一)logstash是什么? logstash是一种分布式日志收集框架,开发语言是JRuby,当然是为了与Java平台对接,不过与Ruby语法兼容良好,非常简洁强大,经常与ElasticSearch ...

  3. CVE-2016-0095提权漏洞分析

    1 前言 瞻仰了k0shl和鹏哥 的漏洞分析,感慨万千,任重而道远. 2 系统环境和工具 windows 7 32旗舰版 windbg 3 poc 3.1poc复现 首先k0shl大佬给出的poc() ...

  4. axios——post请求时把对象obj数据转为formdata格式

    转载自:https://blog.csdn.net/feizhong_web/article/details/80514436  在调用后台接口的时候,上传报名信息,利用axios 的post请求,发 ...

  5. 中国剩余定理模数不互质的情况(poj 2891

    中国剩余定理模数不互质的情况主要有一个ax+by==k*gcd(a,b),注意一下倍数情况和最小 https://vjudge.net/problem/POJ-2891 #include <io ...

  6. day07 linux磁盘分区,ps,kill,df,top命令使用

    day07进入单用户模式删除密码不能进入系统问题: SELINUX=disabled 操作系统linux开机流程加电BIOS找到启动介质先读取第一个扇区(MBR)grup找到kernel加载到内存执行 ...

  7. springboot中的web项目不能访问templates中的静态资源

    方法1: 重新创建文件夹,配置yml文件: spring.resources.static-locations=classpath:/view/ spring.mvc.view.suffix=.htm ...

  8. 大数据、AI“武装”企业服务:风控、检索、安全

    大数据.AI“武装”企业服务:风控.检索.安全 小饭桌创业课堂2017-05-06 15:26:42阅读(127)评论(0) + - 文|吴杨可月 - - 小饭桌创业研究院出品 - 两件秘闻,将美国大 ...

  9. excel中将时间戳转换为日期格式

    将时间戳信息通常为s,将其转换的公式为: =TEXT((A1+8*3600)/86400+70*365+19,"yyyy-mm-dd hh:mm:ss")

  10. Luogu P2845 [USACO15DEC]Switching on the Lights 开关灯(bfs)

    P2845 [USACO15DEC]Switching on the Lights 开关灯 题意 题目背景 来源:usaco-2015-dec \(Farm\ John\)最近新建了一批巨大的牛棚.这 ...