当前位置:网站首页>【LeetCode】14080.数组中的字符串匹配
【LeetCode】14080.数组中的字符串匹配
2022-08-07 01:05:00 【酥酥~】
题目
给你一个字符串数组 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] 都是独一无二的。
题解
暴力
find函数能够查找字符串中是否包含该字串
class Solution {
public:
vector<string> stringMatching(vector<string>& words) {
vector<string> result;
int len = words.size();
for(int i=0;i<len;i++)
{
for(int j=0;j<len;j++)
{
if( i!=j && words[j].find(words[i])!=string::npos)
{
result.emplace_back(words[i]);
break;
}
}
}
return result;
}
};
边栏推荐
猜你喜欢
随机推荐
基于华为云ModelArts和弹性云服务器ECS的AI全流程开发——昇腾工业质检应用实战【华为云至简致远】
The usage of decode()
jvm summary
实时图计算如何进行风控决策管理?
Classic backbone model cheat sheet in CV field (2)
一文了解DataStore(Proto)
NoSuchMethodError异常解析
mysql如何加索引的时候不锁表
[8.6] Code Source - [Prefix Set] [Matrix Game] [Who is the final winner?】
1323_STM32F103_ADC test
数学英语题目理解模型记录(1)
unity UI、 粒子 、3d模型,按钮如何设置显示
【第六篇】商城系统-实现规格参数和销售属性
express学习30-多人管理22验证joi
[Redis] Redis Learning - Three Special Data Types
2022年电工(初级)特种作业证考试题库及模拟考试
Close the Win10 automatic updates
【8.5】代码源 - 【GCD】【序列中位数】【最大连边数量】
time complexity and space complexity
php 生成pdf 图片转pdf









