当前位置:网站首页>【LeetCode】1408. 数组中的字符串匹配
【LeetCode】1408. 数组中的字符串匹配
2022-08-07 03:16:00 【pass night】
题目
给你一个字符串数组 words ,数组中的每个字符串都可以看作是一个单词。请你按 任意 顺序返回 words 中是其他单词的子字符串的所有单词。
如果你可以删除 words[j] 最左侧和/或最右侧的若干字符得到 word[i] ,那么字符串 words[i] 就是 words[j] 的一个子字符串。
示例 1:
输入:words = ["mass","as","hero","superhero"]
输出:["as","hero"]
解释:"as" 是 "mass" 的子字符串,"hero" 是 "superhero" 的子字符串。
["hero","as"] 也是有效的答案。
示例 2:
输入:words = ["leetcode","et","code"]
输出:["et","code"]
解释:"et" 和 "code" 都是 "leetcode" 的子字符串。
示例 3:
输入:words = ["blue","green","bu"]
输出:[]
提示:
1 <= words.length <= 1001 <= words[i].length <= 30words[i]仅包含小写英文字母。- 题目数据 保证 每个
words[i]都是独一无二的。
思路
- 遍历所有字符串,若该字符串是任意一字符串的子串,则添加到结果集当中
代码
class Solution:
def stringMatching(self, words: List[str]) -> List[str]:
ret = []
for x in words:
for y in words:
if x!=y and x in y:
ret.append(x)
break
return ret
复杂度
- 时间复杂度: O ( n 2 L 2 ) O(n^2L^2) O(n2L2)
- 空间复杂度: O ( 1 ) O(1) O(1)
边栏推荐
- 领克09phev主动和被动安全配置齐全,百公里加速5.6s
- 1008: series summation
- 【FLink】Assigned key must not be null
- [转载] swig何许人也
- redis持久化机制的理解
- Yarn学习,Yarn安装,Yarn常用命令。这一篇即可(有需要再补充)
- Coco data set analysis and reading method
- Definition and operation process of OAuth2
- Implement caching mechanism using soft references
- KingbaseES V8R3集群管理维护案例之---集群迁移单实例架构
猜你喜欢
随机推荐
【LeetCode每日一题】——69.x的平方根
Interview experience with points for job hunting + future career planning
C语言从入门到精通 【精读C Prime Plus】【C语言笔记1-4章节】【更新中~】
德迅云安全提供国内卓越、快速、稳定的高防产品
Scala object class basic grammar explanation
haproxy实验
什么是传输网、核心网、承载网、接入网?
Basic usage based on 7.6ElstaicSearch syntax
2333. 最小差值平方和-排序加二分查找,力扣c语言题解
activiti7入门教程
一种用于保证多方子系统数据一致性的方法
STM32 - RTC real-time clock principle + BKP register principle
损失函数_相似度计算_距离计算
Auto.js实现自动删除朋友圈照片
卫星星座1:Starlink星座
@RequestBody
kafka-flink-mysql的流程
Android kotlin实现自定义时钟
1008: 级数求和
2022年NeurIPS智能驾驶大赛









