欢迎光临散文网 会员登陆 & 注册

Leetcode2085.Count Common Words With One Occurrence

2022-02-02 15:35 作者:您是打尖儿还是住店呢  | 我要投稿

Given two string arrays  and , return the number of strings that appear exactly once in each of the two arrays.

 

Example 1:

Input: words1 = ["leetcode","is","amazing","as","is"], words2 = ["amazing","leetcode","is"]Output: 2Explanation:- "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.

Example 2:

Input: words1 = ["b","bb","bbb"], words2 = ["a","aa","aaa"]Output: 0Explanation: There are no strings that appear in each of the two arrays.

Example 3:

Input: words1 = ["a","ab"], words2 = ["a","a","a","ab"]Output: 1Explanation: The only string that appears exactly once in each of the two arrays is "ab".

Runtime: 4 ms, faster than 91.08% of Java online submissions for Count Common Words With One Occurrence.

Memory Usage: 42.3 MB, less than 49.22% of Java online submissions for Count Common Words With One Occurrence.


Leetcode2085.Count Common Words With One Occurrence的评论 (共 条)

分享到微博请遵守国家法律