【力扣100】131.分割回文字符串

添加链接描述

python 复制代码
class Solution:
    def partition(self, s: str) -> List[List[str]]:
        # 思路是回溯
        n=len(s)
        res=[]
        path=[]
        def backtrack(i):
            if i == n:
                res.append(path[:])
                return 
            for j in range(i,n):
                t=s[i:j+1]
                if t==t[::-1]:
                    path.append(t)
                    backtrack(j+1)
                    path.pop()

        backtrack(0)
        return res 

思路是:

  1. 递归加回溯
相关推荐
j7~1 小时前
【穷举、深搜与回溯算法】一棵决策树讲透全排列与子集
数据结构·c++·算法·leetcode·回溯·递归
傅科摆 _ py2 小时前
DP,贪心,堆和栈,二分力扣复习
开发语言·python·算法
Shaoshing3 小时前
LeetCode100 42.接雨水
java·算法·leetcode
域限奇点访客3 小时前
用AI生成问卷的网站怎么选?看题目录入结构、题型映射和生成后的校验
算法
文丑颜不良啊4 小时前
LeetCode1261~1280题目解析
java·leetcode
not coder4 小时前
一文讲通--从树到红黑树
数据结构·算法
octopus_c4 小时前
C++ 入门
开发语言·c++·算法
ZhengEnCi5 小时前
2026年10月30日AI早报:Gemini 4 Carbon登顶、DeepSeek融资1055亿、智元机器人上岗实测
人工智能·算法
强哥聊算力5 小时前
《算力江湖·Intel帝国往事》第三集:安迪·格鲁夫的铁血时代:Intel为什么能把对手逼到墙角?
运维·人工智能·科技·算法·ai·gpu算力
Shaoshing5 小时前
LeetCode100 11. 盛最多水的容器
算法·leetcode