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:)注意这一部分代码

相关推荐
hanlin038 小时前
刷题笔记:力扣第32题-最长有效括号
笔记·算法·leetcode
All for pursuit.8 小时前
【动态规划-21】312.戳气球
数据结构·c++·算法·leetcode·动态规划
Scintilla_y11 小时前
DAY2 滑动窗口
算法·leetcode·散列表
特立独行的猫a12 小时前
仓颉语言UI开发实战:我用仓颉写了个桌面版力扣
算法·leetcode·ui·tauri·仓颉·cj-tarui
y1su12 小时前
Leetcode 动态规划 模板
java·数据结构·算法·leetcode·动态规划
All for pursuit.13 小时前
【位运算-3】136.只出现一次的数字
数据结构·c++·算法·leetcode
All for pursuit.15 小时前
【完结】LeetCodeHot100题 详细解题过程及代码汇总
数据结构·c++·算法·leetcode
mmmmath_316 小时前
LeetCode.101.对称二叉树
数据结构·leetcode
mmmmath_320 小时前
LeetCode.637.二叉树的层平均值
算法·leetcode
Tisfy21 小时前
LeetCode 2913.子数组不同元素数目的平方和 I:第一题先常数很大的O(n^2)
算法·leetcode·题解·模拟·暴力