当前位置:网站首页>day10每日3题(3):数组中的字符串匹配
day10每日3题(3):数组中的字符串匹配
2022-06-26 16:17:00 【程序猿不脱发2】
题目:
给你一个字符串数组 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 <= 100
1 <= words[i].length <= 30
words[i] 仅包含小写英文字母。
题目数据 保证 每个 words[i] 都是独一无二的。
通过
思路:
双重遍历, 尽量减少里层遍历的次数。
java代码:
class Solution {
public List<String> stringMatching(String[] words) {
List<String> res = new ArrayList<>();
for (int i = 0; i < words.length-1; i++) {
for (int j = i+1; j < words.length; j++) {
if (!res.contains(words[j]) && words[i].contains(words[j])) {
res.add(words[j]);
} else if (!res.contains(words[i]) && words[j].contains(words[i])) {
res.add(words[i]);
}
}
}
return res;
}
}
边栏推荐
- Binary array command of redis
- 首例猪心移植细节全面披露:患者体内发现人类疱疹病毒,死后心脏重量翻倍,心肌细胞纤维化丨团队最新论文...
- 【力扣刷题】11.盛最多水的容器//42.接雨水
- Beijing University and Tencent jointly build angel4.0, and the self-developed in-depth learning framework "River map" is integrated into the ecology
- Which position does Anxin securities rank? Is it safe to open an account?
- "C language" question set of ⑩
- LeetCode 单周赛298,前三题
- Failed to get convolution algorithm. This is probably because cuDNN failed to initialize
- Tsinghua's "magic potion" is published in nature: reversing stem cell differentiation, and the achievements of the Nobel Prize go further. Netizen: life can be created without sperm and eggs
- 【力扣刷题】二分查找:4. 寻找两个正序数组的中位数
猜你喜欢

What is the difference between stm32f1 and gd32f1?

Anaconda3安装tensorflow 2.0版本cpu和gpu安装,Win10系统

油田勘探问题

Natural language inference with attention and fine tuning Bert pytorch

Ten thousand words! In depth analysis of the development trend of multi-party data collaborative application and privacy computing under the data security law

长安链交易防重之布谷鸟过滤器

对话长安马自达高层,全新产品将在Q4发布,空间与智能领跑日系

The first batch in the industry! Tencent cloud security and privacy computing products based on angel powerfl passed CFCA evaluation

【蓝桥杯集训100题】scratch辨别质数合数 蓝桥杯scratch比赛专项预测编程题 集训模拟练习题第15题

Développer un opérateur basé sur kubebuilder (démarrer)
随机推荐
R language plotly visualization: Violin graph, multi category variable violin graph, grouped violin graph, split grouped violin graph, two groups of data in each violin graph, each group accounts for
Practice of federal learning in Tencent micro vision advertising
Tencent Peking University's sparse large model training acceleration program het was selected into the VLDB of the international summit
Angel 3.2.0 new version released! Figure the computing power is strengthened again
3 keras版本模型训练
振动式液量检测装置
2 三种建模方式
What is the process of switching C # read / write files from user mode to kernel mode?
基于 MATLAB的自然过渡配音处理方案探究
今年高考英语AI得分134,复旦武大校友这项研究有点意思
10 tf. data
Arduino uno + DS1302 simple time acquisition and serial port printing
MHA switching (recommended operation process)
Solidus labs welcomes zhaojiali, former head of financial innovation in Hong Kong, as a strategic adviser
Anaconda3安装tensorflow 2.0版本cpu和gpu安装,Win10系统
4 自定义模型训练
【从删库到跑路】MySQL基础 完结篇(入个门先跑路了。。)
【小5聊】毕业8年,一直在追梦的路上
当一个程序员一天被打扰 10 次,后果很惊人!
R语言广义线性模型函数GLM、glm函数构建逻辑回归模型(Logistic regression)、分析模型是否过离散(Overdispersion)、使用残差偏差与二项式模型中的剩余自由度的比率评估