Class Solution
java.lang.Object
g2001_2100.s2085_count_common_words_with_one_occurrence.Solution
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 = [“leetcode”,“is”,“amazing”,“as”,“is”], words2 = [“amazing”,“leetcode”,“is”]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong></p>
<ul>
<li>
<p>“leetcode” appears exactly once in each of the two arrays. We count this string.</p>
</li>
<li>
<p>“amazing” appears exactly once in each of the two arrays. We count this string.</p>
</li>
<li>
<p>“is” 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>“as” 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 = [“b”,“bb”,“bbb”], words2 = [“a”,“aa”,“aaa”]</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 = [“a”,“ab”], words2 = [“a”,“a”,“a”,“ab”]</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 “ab”.</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 Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
countWords
-