原题地址:https://oj.leetcode.com/problems/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:
# @param s, a string
# @return a list of lists of string
def isPalindrome(self, s):
for i in range(len(s)):
if s[i] != s[len(s)-1-i]: return False
return True def dfs(self, s, stringlist):
if len(s) == 0: Solution.res.append(stringlist)
for i in range(1, len(s)+1):
if self.isPalindrome(s[:i]):
self.dfs(s[i:], stringlist+[s[:i]]) def partition(self, s):
Solution.res = []
self.dfs(s, [])
return Solution.res

最新文章

  1. 为什么目前没有"成熟"的cookie插件?
  2. 大话数据结构(五)(java程序)——顺序存储结构的插入与删除
  3. Java——Image 图片合并
  4. ADO.NET笔记——读取二进制大对象(BLOB)
  5. window2008 64位系统没有office组件问题分析及解决
  6. 使用blktrace排查iowait cpu高的问题
  7. Migrating from IntelliJ Projects
  8. Android开发--去掉标题栏
  9. 转:Visual Studio进行Web性能测试- Part III
  10. PA模块常用表
  11. Python实操
  12. Codeforces Round #419 (Div. 2) ABC
  13. glide引出恶心的git submodule
  14. Ubuntu Server 命令行下的默认语言改为英语en_US.UTF-8
  15. Spring之强制修改某个方法的行为(Arbitrary method replacement)
  16. MySQL使用全文索引(fulltext index)---高性能
  17. Linux下tar.gz 安装
  18. P4782 【模板】2-SAT 问题 && 2-SAT问题
  19. Linux上的free命令简介
  20. string 转 java对象、转map的方式

热门文章

  1. 初识thinkphp(5)
  2. CPU的主频
  3. HttpServlet Service方法
  4. linux Shell 脚本编写
  5. P4811 C’s problem(c)
  6. Codeforces Round #371 (Div. 1) C. Sonya and Problem Wihtout a Legend 贪心
  7. 使用CefSharp在.Net程序中嵌入Chrome浏览器(七)——右键菜单
  8. STM32 CRC-32 Calculator Unit
  9. Golang 版本发布 与 TIOBE 排名
  10. 8张图理解Java---importnew---programcreek