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

相关推荐
_Itachi__2 小时前
LeetCode 热题 100 283. 移动零
数据结构·算法·leetcode
鱼不如渔3 小时前
leetcode刷题第十三天——二叉树Ⅲ
linux·算法·leetcode
南宫生4 小时前
力扣每日一题【算法学习day.131】
java·学习·算法·leetcode
武乐乐~13 小时前
欢乐力扣:赎金信
算法·leetcode·职场和发展
sjsjs1116 小时前
【数据结构-并查集】力扣1202. 交换字符串中的元素
数据结构·leetcode·并查集
Onlooker12917 小时前
LC-单词搜索、分割回文串、N皇后、搜索插入位置、搜索二维矩阵
算法·leetcode
且听风吟ayan19 小时前
leetcode day19 844+977
leetcode·c#
MiyamiKK5719 小时前
leetcode_位运算 190.颠倒二进制位
python·算法·leetcode
C137的本贾尼19 小时前
解决 LeetCode 串联所有单词的子串问题
算法·leetcode·c#
Joyner201820 小时前
python-leetcode-找到字符串中所有字母异位词
算法·leetcode·职场和发展