Skip to content

Commit 4df546c

Browse files
committed
Added README.md file for Count Prefixes of a Given String
1 parent e69c30e commit 4df546c

File tree

1 file changed

+34
-0
lines changed
  • 2341-count-prefixes-of-a-given-string

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<h2><a href="https://leetcode.com/problems/count-prefixes-of-a-given-string">Count Prefixes of a Given String</a></h2> <img src='https://img.shields.io/badge/Difficulty-Easy-brightgreen' alt='Difficulty: Easy' /><hr><p>You are given a string array <code>words</code> and a string <code>s</code>, where <code>words[i]</code> and <code>s</code> comprise only of <strong>lowercase English letters</strong>.</p>
2+
3+
<p>Return <em>the <strong>number of strings</strong> in</em> <code>words</code> <em>that are a <strong>prefix</strong> of</em> <code>s</code>.</p>
4+
5+
<p>A <strong>prefix</strong> of a string is a substring that occurs at the beginning of the string. A <b>substring</b> is a contiguous sequence of characters within a string.</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong class="example">Example 1:</strong></p>
9+
10+
<pre>
11+
<strong>Input:</strong> words = [&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;ab&quot;,&quot;bc&quot;,&quot;abc&quot;], s = &quot;abc&quot;
12+
<strong>Output:</strong> 3
13+
<strong>Explanation:</strong>
14+
The strings in words which are a prefix of s = &quot;abc&quot; are:
15+
&quot;a&quot;, &quot;ab&quot;, and &quot;abc&quot;.
16+
Thus the number of strings in words which are a prefix of s is 3.</pre>
17+
18+
<p><strong class="example">Example 2:</strong></p>
19+
20+
<pre>
21+
<strong>Input:</strong> words = [&quot;a&quot;,&quot;a&quot;], s = &quot;aa&quot;
22+
<strong>Output:</strong> 2
23+
<strong>Explanation:
24+
</strong>Both of the strings are a prefix of s.
25+
Note that the same string can occur multiple times in words, and it should be counted each time.</pre>
26+
27+
<p>&nbsp;</p>
28+
<p><strong>Constraints:</strong></p>
29+
30+
<ul>
31+
<li><code>1 &lt;= words.length &lt;= 1000</code></li>
32+
<li><code>1 &lt;= words[i].length, s.length &lt;= 10</code></li>
33+
<li><code>words[i]</code> and <code>s</code> consist of lowercase English letters <strong>only</strong>.</li>
34+
</ul>

0 commit comments

Comments
 (0)