Skip to content

Commit 1b583fb

Browse files
committed
Create README - LeetHub
1 parent c69eb25 commit 1b583fb

File tree

1 file changed

+50
-0
lines changed
  • 2047-number-of-valid-words-in-a-sentence

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<h2><a href="https://leetcode.com/problems/number-of-valid-words-in-a-sentence">2047. Number of Valid Words in a Sentence</a></h2><h3>Easy</h3><hr><p>A sentence consists of lowercase letters (<code>&#39;a&#39;</code> to <code>&#39;z&#39;</code>), digits (<code>&#39;0&#39;</code> to <code>&#39;9&#39;</code>), hyphens (<code>&#39;-&#39;</code>), punctuation marks (<code>&#39;!&#39;</code>, <code>&#39;.&#39;</code>, and <code>&#39;,&#39;</code>), and spaces (<code>&#39; &#39;</code>) only. Each sentence can be broken down into <strong>one or more tokens</strong> separated by one or more spaces <code>&#39; &#39;</code>.</p>
2+
3+
<p>A token is a valid word if <strong>all three</strong> of the following are true:</p>
4+
5+
<ul>
6+
<li>It only contains lowercase letters, hyphens, and/or punctuation (<strong>no</strong> digits).</li>
7+
<li>There is <strong>at most one</strong> hyphen <code>&#39;-&#39;</code>. If present, it <strong>must</strong> be surrounded by lowercase characters (<code>&quot;a-b&quot;</code> is valid, but <code>&quot;-ab&quot;</code> and <code>&quot;ab-&quot;</code> are not valid).</li>
8+
<li>There is <strong>at most one</strong> punctuation mark. If present, it <strong>must</strong> be at the <strong>end</strong> of the token (<code>&quot;ab,&quot;</code>, <code>&quot;cd!&quot;</code>, and <code>&quot;.&quot;</code> are valid, but <code>&quot;a!b&quot;</code> and <code>&quot;c.,&quot;</code> are not valid).</li>
9+
</ul>
10+
11+
<p>Examples of valid words include <code>&quot;a-b.&quot;</code>, <code>&quot;afad&quot;</code>, <code>&quot;ba-c&quot;</code>, <code>&quot;a!&quot;</code>, and <code>&quot;!&quot;</code>.</p>
12+
13+
<p>Given a string <code>sentence</code>, return <em>the <strong>number</strong> of valid words in </em><code>sentence</code>.</p>
14+
15+
<p>&nbsp;</p>
16+
<p><strong class="example">Example 1:</strong></p>
17+
18+
<pre>
19+
<strong>Input:</strong> sentence = &quot;<u>cat</u> <u>and</u> <u>dog</u>&quot;
20+
<strong>Output:</strong> 3
21+
<strong>Explanation:</strong> The valid words in the sentence are &quot;cat&quot;, &quot;and&quot;, and &quot;dog&quot;.
22+
</pre>
23+
24+
<p><strong class="example">Example 2:</strong></p>
25+
26+
<pre>
27+
<strong>Input:</strong> sentence = &quot;!this 1-s b8d!&quot;
28+
<strong>Output:</strong> 0
29+
<strong>Explanation:</strong> There are no valid words in the sentence.
30+
&quot;!this&quot; is invalid because it starts with a punctuation mark.
31+
&quot;1-s&quot; and &quot;b8d&quot; are invalid because they contain digits.
32+
</pre>
33+
34+
<p><strong class="example">Example 3:</strong></p>
35+
36+
<pre>
37+
<strong>Input:</strong> sentence = &quot;<u>alice</u> <u>and</u> <u>bob</u> <u>are</u> <u>playing</u> stone-game10&quot;
38+
<strong>Output:</strong> 5
39+
<strong>Explanation:</strong> The valid words in the sentence are &quot;alice&quot;, &quot;and&quot;, &quot;bob&quot;, &quot;are&quot;, and &quot;playing&quot;.
40+
&quot;stone-game10&quot; is invalid because it contains digits.
41+
</pre>
42+
43+
<p>&nbsp;</p>
44+
<p><strong>Constraints:</strong></p>
45+
46+
<ul>
47+
<li><code>1 &lt;= sentence.length &lt;= 1000</code></li>
48+
<li><code>sentence</code> only contains lowercase English letters, digits, <code>&#39; &#39;</code>, <code>&#39;-&#39;</code>, <code>&#39;!&#39;</code>, <code>&#39;.&#39;</code>, and <code>&#39;,&#39;</code>.</li>
49+
<li>There will be at least&nbsp;<code>1</code> token.</li>
50+
</ul>

0 commit comments

Comments
 (0)