题目
给你两个字符串数组 words1
和 words2
,请你返回在两个字符串数组中 都恰好出现一次 的字符串的数目。
示例1:
1 | 输入:words1 = ["leetcode","is","amazing","as","is"], words2 = ["amazing","leetcode","is"] |
示例2:
1 | 输入:words1 = ["b","bb","bbb"], words2 = ["a","aa","aaa"] |
示例3:
1 | 输入:words1 = ["a","ab"], words2 = ["a","a","a","ab"] |
提示:
1 <= words1.length, words2.length <= 1000
1 <= words1[i].length, words2[j].length <= 30
words1[i]
和words2[j]
都只包含小写英文字母。
解法
解法一:
Java
1 | public int countWords(String[] words1, String[] words2) { |