写作网站好吗,做盗版电影网站后果,瑶海区网站建设公司,爱空间装修公司口碑怎么样文章目录1. 题目2. 解题1. 题目
给你一个字符串数组 patterns 和一个字符串 word #xff0c;统计 patterns 中有多少个字符串是 word 的子字符串。 返回字符串数目。
子字符串 是字符串中的一个连续字符序列。
示例 1#xff1a;
输入#xff1a;patterns [a统计 patterns 中有多少个字符串是 word 的子字符串。 返回字符串数目。
子字符串 是字符串中的一个连续字符序列。
示例 1
输入patterns [a,abc,bc,d], word abc
输出3
解释
- a 是 abc 的子字符串。
- abc 是 abc 的子字符串。
- bc 是 abc 的子字符串。
- d 不是 abc 的子字符串。
patterns 中有 3 个字符串作为子字符串出现在 word 中。示例 2
输入patterns [a,b,c], word aaaaabbbbb
输出2
解释
- a 是 aaaaabbbbb 的子字符串。
- b 是 aaaaabbbbb 的子字符串。
- c 不是 aaaaabbbbb 的字符串。
patterns 中有 2 个字符串作为子字符串出现在 word 中。示例 3
输入patterns [a,a,a], word ab
输出3
解释patterns 中的每个字符串都作为子字符串出现在 word ab 中。提示
1 patterns.length 100
1 patterns[i].length 100
1 word.length 100
patterns[i] 和 word 由小写英文字母组成来源力扣LeetCode 链接https://leetcode-cn.com/problems/number-of-strings-that-appear-as-substrings-in-word 著作权归领扣网络所有。商业转载请联系官方授权非商业转载请注明出处。 2. 解题
class Solution:def numOfStrings(self, patterns: List[str], word: str) - int:ans 0for p in patterns:if p in word:ans 1return ans24 ms 15.1 MB Python3
class Solution {
public:int numOfStrings(vectorstring patterns, string word) {int ans 0;for(auto p : patterns){if(word.find(p) ! string::npos)ans;}return ans;}
};8 ms 8.4 MB C 我的CSDN博客地址 https://michael.blog.csdn.net/
长按或扫码关注我的公众号Michael阿明一起加油、一起学习进步