|
| 1 | +<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 <b>each</b> of the two arrays.</em></p> |
| 2 | + |
| 3 | +<p> </p> |
| 4 | +<p><strong class="example">Example 1:</strong></p> |
| 5 | + |
| 6 | +<pre> |
| 7 | +<strong>Input:</strong> words1 = ["leetcode","is","amazing","as","is"], words2 = ["amazing","leetcode","is"] |
| 8 | +<strong>Output:</strong> 2 |
| 9 | +<strong>Explanation:</strong> |
| 10 | +- "leetcode" appears exactly once in each of the two arrays. We count this string. |
| 11 | +- "amazing" appears exactly once in each of the two arrays. We count this string. |
| 12 | +- "is" appears in each of the two arrays, but there are 2 occurrences of it in words1. We do not count this string. |
| 13 | +- "as" appears once in words1, but does not appear in words2. We do not count this string. |
| 14 | +Thus, there are 2 strings that appear exactly once in each of the two arrays. |
| 15 | +</pre> |
| 16 | + |
| 17 | +<p><strong class="example">Example 2:</strong></p> |
| 18 | + |
| 19 | +<pre> |
| 20 | +<strong>Input:</strong> words1 = ["b","bb","bbb"], words2 = ["a","aa","aaa"] |
| 21 | +<strong>Output:</strong> 0 |
| 22 | +<strong>Explanation:</strong> There are no strings that appear in each of the two arrays. |
| 23 | +</pre> |
| 24 | + |
| 25 | +<p><strong class="example">Example 3:</strong></p> |
| 26 | + |
| 27 | +<pre> |
| 28 | +<strong>Input:</strong> words1 = ["a","ab"], words2 = ["a","a","a","ab"] |
| 29 | +<strong>Output:</strong> 1 |
| 30 | +<strong>Explanation:</strong> The only string that appears exactly once in each of the two arrays is "ab". |
| 31 | +</pre> |
| 32 | + |
| 33 | +<p> </p> |
| 34 | +<p><strong>Constraints:</strong></p> |
| 35 | + |
| 36 | +<ul> |
| 37 | + <li><code>1 <= words1.length, words2.length <= 1000</code></li> |
| 38 | + <li><code>1 <= words1[i].length, words2[j].length <= 30</code></li> |
| 39 | + <li><code>words1[i]</code> and <code>words2[j]</code> consists only of lowercase English letters.</li> |
| 40 | +</ul> |
0 commit comments