Class Solution

java.lang.Object
g0801_0900.s0819_most_common_word.Solution

public class Solution extends Object
819 - Most Common Word.<p>Easy</p> <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> <p>The words in <code>paragraph</code> are <strong>case-insensitive</strong> and the answer should be returned in <strong>lowercase</strong>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> paragraph = &ldquo;Bob hit a ball, the hit BALL flew far after it was hit.&rdquo;, banned = [&ldquo;hit&rdquo;]</p> <p><strong>Output:</strong> &ldquo;ball&rdquo;</p> <p><strong>Explanation:</strong> &ldquo;hit&rdquo; occurs 3 times, but it is a banned word. &ldquo;ball&rdquo; occurs twice (and no other word does), so it is the most frequent non-banned word in the paragraph. Note that words in the paragraph are not case sensitive, that punctuation is ignored (even if adjacent to words, such as &ldquo;ball,&rdquo;), and that &ldquo;hit&rdquo; isn&rsquo;t the answer even though it occurs more because it is banned.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> paragraph = &ldquo;a.&rdquo;, banned = []</p> <p><strong>Output:</strong> &ldquo;a&rdquo;</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= paragraph.length <= 1000</code></li> <li>paragraph consists of English letters, space <code>' '</code>, or one of the symbols: <code>&quot;!?',;.&quot;</code>.</li> <li><code>0 <= banned.length <= 100</code></li> <li><code>1 <= banned[i].length <= 10</code></li> <li><code>banned[i]</code> consists of only lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details