技术栈

472. Concatenated Words

ujn201612222024-09-09 17:43

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

上一篇:在jenkins中获取git的修改记录的方法
下一篇:Android 12 SystemUI下拉状态栏禁止QuickQSPanel展开
相关推荐
文丑颜不良啊
4 小时前
LeetCode3001~3020题目解析
java·leetcode
Pniubi
11 小时前
力扣19 . 删除表的倒数第N个节点(栈)
算法·leetcode·职场和发展
文丑颜不良啊
1 天前
LeetCode2761~2780题目解析
java·leetcode
文丑颜不良啊
1 天前
LeetCode2841~2860题目解析
java·leetcode
文丑颜不良啊
1 天前
LeetCode2921~2940题目解析
java·leetcode
文丑颜不良啊
1 天前
LeetCode2901~2920题目解析
java·leetcode
文丑颜不良啊
1 天前
LeetCode2861~2880题目解析
java·leetcode
文丑颜不良啊
2 天前
LeetCode2821~2840题目解析
java·leetcode
Pniubi
2 天前
力扣24. 两两交换链表中的节点(递归)
算法·leetcode·链表
文丑颜不良啊
2 天前
LeetCode2741~2760题目解析
java·leetcode
热门推荐
01国内可直接用、免费额度/永久免费的大模型API清单(含 SiliconFlow、火山、阿里、智谱、百度、Kimi、DeepSeek、DMXAPI 等)02历年考研数学一、数学二、数学三真题试卷及答案PDF03几个好用的ip纯净度检测网站04微信历史版本含下载地址( Windows PC | 安卓 | MAC )及设置微信不更新05GitHub 镜像站点06昇腾910B系列芯片完全指南:四款型号对比、服务器选型与大模型部署实战07蜘蛛磁力 搜索引擎大全,如何使用蜘蛛磁力查找磁力链接08苹果iPA游戏软件资源下载网站09如何新建文件夹? 电脑新建文件夹的4种方法10Dify:一站式AI应用开发平台全解析与Windows部署指南