472. Concatenated Words

https://leetcode.com/problems/concatenated-words/description/?envType=company&envId=tiktok&favoriteSlug=tiktok-three-months

python 复制代码
class Solution:
    def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:
        ws=set(words)
        ml=min(map(len,words))

        @cache
        def is_concat(word):
            for i in range(ml,len(word)-ml+1):
                if word[:i] in ws and (word[i:] in ws or is_concat(word[i:])):
                    return True    
            return False
        return [w for w in words if is_concat(w)]
            

(word[i:] in ws or is_concat(word[i:])注意这一部分代码

相关推荐
hn小菜鸡8 小时前
LeetCode 377.组合总和IV
数据结构·算法·leetcode
亮亮爱刷题10 天前
飞往大厂梦之算法提升-7
数据结构·算法·leetcode·动态规划
zmuy10 天前
124. 二叉树中的最大路径和
数据结构·算法·leetcode
chao_78910 天前
滑动窗口题解——找到字符串中所有字母异位词【LeetCode】
数据结构·算法·leetcode
Alfred king10 天前
面试150跳跃游戏
python·leetcode·游戏·贪心算法
呆呆的小鳄鱼10 天前
leetcode:746. 使用最小花费爬楼梯
算法·leetcode·职场和发展
YuTaoShao10 天前
【LeetCode 热题 100】42. 接雨水——(解法一)前后缀分解
java·算法·leetcode·职场和发展
YuforiaCode10 天前
(LeetCode 面试经典 150 题) 27.移除元素
算法·leetcode·面试
呆呆的小鳄鱼10 天前
leetcode:98. 验证二叉搜索树
算法·leetcode·职场和发展
alphaTao10 天前
LeetCode 每日一题 2025/6/16-2025/6/22
算法·leetcode