博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
131. Palindrome Partitioning
阅读量:4259 次
发布时间:2019-05-26

本文共 1151 字,大约阅读时间需要 3 分钟。

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”]
]

思路:此题第一思路就是回溯,然后就是回溯算法的固定思路解此类问题了。

bool isSubPailndrome(string& str, int low, int high){    if (low == high)return true;    while (low <= high){        if (str[low] == str[high])low++, high--;        else return false;    }    return true;}void dfs_partition(string& s, int start, int end, vector
& path, vector
>& res){ if (end == s.size()){ if (isSubPailndrome(s, start,end - 1)){ path.push_back(s.substr(start, end - start)); res.push_back(path); path.pop_back(); } return; } if (isSubPailndrome(s,start,end - 1)){ path.push_back(s.substr(start, end - start)); dfs_partition(s, end, end + 1, path, res); path.pop_back(); } dfs_partition(s, start, end + 1, path, res);}vector
> partition(string s) { vector
> res; if (s == "")return res; vector
path; dfs_partition(s, 0, 1, path, res); return res;}

转载地址:http://esxei.baihongyu.com/

你可能感兴趣的文章
C/C++输入输出
查看>>
泸州NGN属南气矿工程----华为s2600磁盘阵列问题解决
查看>>
泸州属南气矿----配置S2600磁盘阵列报错:There is no master controller.
查看>>
SQL 调优1
查看>>
OA报账规范(出差专用)
查看>>
生产库快速关闭数据库
查看>>
差异增量备份和累积增量备份的差别
查看>>
ASM 无法发现候选磁盘组----grid 11.2.0.3 asm 自检通不过 prvf-5184
查看>>
ASM 无法发现候选磁盘组----丢失的ASM磁盘组 ASM的磁盘组无法挂载
查看>>
Oracle 10g配置单向stream流复制,完整记录
查看>>
ORA-00845 MEMORY_TARGET not supported on this system
查看>>
ORA-00257: archiver error --11GR2 RAC 设置归档路径和开启flashback
查看>>
奕新集团项目--Oracle 源RAC ---目标 RAC GG 搭建 11.2.3 版本 双向同步
查看>>
What is SCAN in Oracle 11g R2 RAC
查看>>
关于Recycle Bin是什么以及实验
查看>>
Linux搭建时间同步服务器
查看>>
ORA-12541: TNS:no listener
查看>>
mysql数据库存储路径更改 数据文件位置
查看>>
Could not fetch specs from https://rubygems.org/
查看>>
oracle日志分析工具LogMiner使用
查看>>