|
| 1 | +<h2><a href="https://leetcode.com/problems/most-common-word/">819. Most Common Word</a></h2><h3>Easy</h3><hr><div><p>Given a string <code>paragraph</code> and a string array of the banned words <code>banned</code>, return <em>the most frequent word that is not banned</em>. It is <strong>guaranteed</strong> there is <strong>at least one word</strong> that is not banned, and that the answer is <strong>unique</strong>.</p> |
| 2 | + |
| 3 | +<p>The words in <code>paragraph</code> are <strong>case-insensitive</strong> and the answer should be returned in <strong>lowercase</strong>.</p> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong>Example 1:</strong></p> |
| 7 | + |
| 8 | +<pre><strong>Input:</strong> paragraph = "Bob hit a ball, the hit BALL flew far after it was hit.", banned = ["hit"] |
| 9 | +<strong>Output:</strong> "ball" |
| 10 | +<strong>Explanation:</strong> |
| 11 | +"hit" occurs 3 times, but it is a banned word. |
| 12 | +"ball" occurs twice (and no other word does), so it is the most frequent non-banned word in the paragraph. |
| 13 | +Note that words in the paragraph are not case sensitive, |
| 14 | +that punctuation is ignored (even if adjacent to words, such as "ball,"), |
| 15 | +and that "hit" isn't the answer even though it occurs more because it is banned. |
| 16 | +</pre> |
| 17 | + |
| 18 | +<p><strong>Example 2:</strong></p> |
| 19 | + |
| 20 | +<pre><strong>Input:</strong> paragraph = "a.", banned = [] |
| 21 | +<strong>Output:</strong> "a" |
| 22 | +</pre> |
| 23 | + |
| 24 | +<p> </p> |
| 25 | +<p><strong>Constraints:</strong></p> |
| 26 | + |
| 27 | +<ul> |
| 28 | + <li><code>1 <= paragraph.length <= 1000</code></li> |
| 29 | + <li>paragraph consists of English letters, space <code>' '</code>, or one of the symbols: <code>"!?',;."</code>.</li> |
| 30 | + <li><code>0 <= banned.length <= 100</code></li> |
| 31 | + <li><code>1 <= banned[i].length <= 10</code></li> |
| 32 | + <li><code>banned[i]</code> consists of only lowercase English letters.</li> |
| 33 | +</ul> |
| 34 | +</div> |
0 commit comments