2085. Count Common Words With One Occurrence Easy
1/**
2 * [2085] Count Common Words With One Occurrence
3 *
4 * Given two string arrays words1 and words2, return the number of strings that appear exactly once in each of the two arrays.
5 *
6 * Example 1:
7 *
8 * Input: words1 = ["leetcode","is","amazing","as","is"], words2 = ["amazing","leetcode","is"]
9 * Output: 2
10 * Explanation:
11 * - "leetcode" appears exactly once in each of the two arrays. We count this string.
12 * - "amazing" appears exactly once in each of the two arrays. We count this string.
13 * - "is" appears in each of the two arrays, but there are 2 occurrences of it in words1. We do not count this string.
14 * - "as" appears once in words1, but does not appear in words2. We do not count this string.
15 * Thus, there are 2 strings that appear exactly once in each of the two arrays.
16 *
17 * Example 2:
18 *
19 * Input: words1 = ["b","bb","bbb"], words2 = ["a","aa","aaa"]
20 * Output: 0
21 * Explanation: There are no strings that appear in each of the two arrays.
22 *
23 * Example 3:
24 *
25 * Input: words1 = ["a","ab"], words2 = ["a","a","a","ab"]
26 * Output: 1
27 * Explanation: The only string that appears exactly once in each of the two arrays is "ab".
28 *
29 *
30 * Constraints:
31 *
32 * 1 <= words1.length, words2.length <= 1000
33 * 1 <= words1[i].length, words2[j].length <= 30
34 * words1[i] and words2[j] consists only of lowercase English letters.
35 *
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/count-common-words-with-one-occurrence/
40// discuss: https://leetcode.com/problems/count-common-words-with-one-occurrence/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45 pub fn count_words(words1: Vec<String>, words2: Vec<String>) -> i32 {
46 0
47 }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn test_2085() {
58 }
59}
60
Back
© 2025 bowen.ge All Rights Reserved.