Advertisement
2185. Counting Words With a Given Prefix
EasyView on LeetCode
Time: O(n * p)
Space: O(1)
Approach
Count words where w.StartsWith(pref) is true.
2185.cs
C#
// Approach: Count words where w.StartsWith(pref) is true.
// Time: O(n * p) Space: O(1)
public class Solution
{
public int PrefixCount(string[] words, string pref)
{
return words.Count(w => w.StartsWith(pref));
}
}Advertisement
Was this solution helpful?