class Solution(object):
def partition(self, s):
"""
:type s: str
:rtype: List[List[str]]
"""
# https://discuss.leetcode.com/topic/6186/java-backtracking-solution/2
result = []
curr = []
self.recurPartition(result, curr, s, 0)
return result
def recurPartition(self, result, curr, s, start):
if start == len(s):
result.append(list(curr))
for i in range(start, len(s)):
if self.isPalindrome(s, start, i):
curr.append(s[start:i + 1])
self.recurPartition(result, curr, s, i + 1)
curr.pop()
def isPalindrome(self, s, begin, end):
while begin < end:
if s[begin] != s[end]:
return False
begin += 1
end -= 1
return True
python-leetcode面试题解之第131题分割回文串-题解.zip
需积分: 1 141 浏览量
2024-05-07
05:55:52
上传
评论
收藏 940B ZIP 举报
Ddddddd_158
- 粉丝: 1306
- 资源: 324
最新资源
- tensorflow-2.9.3-cp39-cp39-win-amd64.whl
- tensorflow-2.9.3-cp37-cp37m-win-amd64.whl
- tensorflow-gpu-2.9.2-cp37-cp37m-win-amd64.whl
- matlab的低通,高通,带通滤波器代码设计
- 系统字体下载 字体文件-仿宋-黑体-楷体-楷体-GB2312-宋体-常规 文件.zip
- 演示设计-PPT模板-水墨风格-艺术与文化展示-水墨风格PPT模板:优雅设计,适合艺术与文化演示.zip
- view_video.php.html
- 涂个壁纸.apk
- hot-spicy pot.csv
- 二进制格式的BPSK中频数据,可以用来进行解调系统的开发
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈