java.lang.Object
g2001_2100.s2085_count_common_words_with_one_occurrence.Solution

public class Solution extends Object
2085 - Count Common Words With One Occurrence.<p>Easy</p> <p>Given two string arrays <code>words1</code> and <code>words2</code>, return <em>the number of strings that appear <strong>exactly once</strong> in <strong>each</strong> of the two arrays.</em></p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> words1 = [&ldquo;leetcode&rdquo;,&ldquo;is&rdquo;,&ldquo;amazing&rdquo;,&ldquo;as&rdquo;,&ldquo;is&rdquo;], words2 = [&ldquo;amazing&rdquo;,&ldquo;leetcode&rdquo;,&ldquo;is&rdquo;]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong></p> <ul> <li> <p>&ldquo;leetcode&rdquo; appears exactly once in each of the two arrays. We count this string.</p> </li> <li> <p>&ldquo;amazing&rdquo; appears exactly once in each of the two arrays. We count this string.</p> </li> <li> <p>&ldquo;is&rdquo; appears in each of the two arrays, but there are 2 occurrences of it in words1. We do not count this string.</p> </li> <li> <p>&ldquo;as&rdquo; appears once in words1, but does not appear in words2. We do not count this string.</p> </li> </ul> <p>Thus, there are 2 strings that appear exactly once in each of the two arrays.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> words1 = [&ldquo;b&rdquo;,&ldquo;bb&rdquo;,&ldquo;bbb&rdquo;], words2 = [&ldquo;a&rdquo;,&ldquo;aa&rdquo;,&ldquo;aaa&rdquo;]</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> There are no strings that appear in each of the two arrays.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> words1 = [&ldquo;a&rdquo;,&ldquo;ab&rdquo;], words2 = [&ldquo;a&rdquo;,&ldquo;a&rdquo;,&ldquo;a&rdquo;,&ldquo;ab&rdquo;]</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> The only string that appears exactly once in each of the two arrays is &ldquo;ab&rdquo;.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= words1.length, words2.length <= 1000</code></li> <li><code>1 <= words1[i].length, words2[j].length <= 30</code></li> <li><code>words1[i]</code> and <code>words2[j]</code> consists only of lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • countWords

      public int countWords(String[] words1, String[] words2)