1967. Number of Strings That Appear as Substrings in Word
UnknownView on LeetCode
Time: O(p * n)
Space: O(1)
Problem Overview
Number of Strings That Appear as Substrings in Word (Unknown) asks you to solve a structured algorithmic task. This is a common String pattern in coding interviews. Count patterns where word.Contains(pattern) is true.
A full step-by-step explanation is being added. See the study guide for pattern-based practice.
Approach
Count patterns where word.Contains(pattern) is true.
Related patterns: String
1967.cs
C#
// Approach: Count patterns where word.Contains(pattern) is true.
// Time: O(p * n) Space: O(1)
public class Solution
{
public int NumOfStrings(string[] patterns, string word)
{
return patterns.Count(pattern => word.Contains(pattern));
}
}Was this solution helpful?
Related Problems
- 12. Integer to Roman(Medium)
- 13. Roman to Integer(Easy)
- 14. Longest Common Prefix(Easy)
- 20. Valid Parentheses(Easy)
- 22. Generate Parentheses(Medium)
- 30. Substring with Concatenation of All Words(Hard)