[LeetCode]#1967. Number of Strings That Appear as Substrings in Word

Input: patterns = ["a","abc","bc","d"], word = "abc"
Output: 3
Explanation:
- "a" appears as a substring in "abc".
- "abc" appears as a substring in "abc".
- "bc" appears as a substring in "abc".
- "d" does not appear as a substring in "abc".
3 of the strings in patterns appear as a substring in word.
  1. Check patterns is in word.
  2. If yes, ans=ans+1
  3. return ans
class Solution:
def numOfStrings(self, patterns, word):
ans=0
for i in patterns:
if i in word:
ans+=1
return ans

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store