2022-03-27 20:38:29 +08:00
< 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 >
< p > < / p >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 1:< / strong > < / p >
2022-03-27 20:38:29 +08:00
< pre >
< strong > Input:< / strong > words1 = [" leetcode" ," is" ," amazing" ," as" ," is" ], words2 = [" amazing" ," leetcode" ," is" ]
< strong > Output:< / strong > 2
< strong > Explanation:< / strong >
- " leetcode" appears exactly once in each of the two arrays. We count this string.
- " amazing" appears exactly once in each of the two arrays. We count this string.
- " is" appears in each of the two arrays, but there are 2 occurrences of it in words1. We do not count this string.
- " as" appears once in words1, but does not appear in words2. We do not count this string.
Thus, there are 2 strings that appear exactly once in each of the two arrays.
< / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 2:< / strong > < / p >
2022-03-27 20:38:29 +08:00
< pre >
< strong > Input:< / strong > words1 = [" b" ," bb" ," bbb" ], words2 = [" a" ," aa" ," aaa" ]
< strong > Output:< / strong > 0
< strong > Explanation:< / strong > There are no strings that appear in each of the two arrays.
< / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 3:< / strong > < / p >
2022-03-27 20:38:29 +08:00
< pre >
< strong > Input:< / strong > words1 = [" a" ," ab" ], words2 = [" a" ," a" ," a" ," ab" ]
< strong > Output:< / strong > 1
< strong > Explanation:< / strong > The only string that appears exactly once in each of the two arrays is " ab" .
< / pre >
< p > < / 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 >