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

(wordi: in ws or is_concat(wordi:)注意这一部分代码

相关推荐
青山木1 小时前
枚举类DP进阶:完全平方数与零钱兑换
java·数据结构·算法·leetcode·动态规划
土司大王15 小时前
LeetCode hot100 回溯专题总结:Java 通用模板、决策树模型
java·算法·leetcode·决策树
a1879272183117 小时前
【算法】链表(二):链表上的双指针——变速、异链与定距,和一份路程账本
数据结构·算法·leetcode·链表·go·指针·环形链表
hanlin0321 小时前
刷题笔记:力扣第287题-寻找重复数
笔记·算法·leetcode
橘子汽水1681 天前
Leetcode 322 279 零钱兑换,完全平方数
算法·leetcode
土司大王1 天前
LeetCode hot100——51.N 皇后:Java 回溯模板、列与对角线剪枝、O(n!) 复杂度分析
java·leetcode·剪枝
木井巳1 天前
【记忆化搜索】斐波那契数
java·算法·leetcode·深度优先·剪枝·推荐算法
Navigator_Z2 天前
LeetCode //C - 1240. Tiling a Rectangle with the Fewest Squares
c语言·算法·leetcode
稻米哟2 天前
力扣100——双指针
算法·leetcode