力扣2085.统计出现过一次的公共字符串

思路:哈希表,创建俩个字典记录俩个字符串数组的各自字符串出现次数,每有一个字符俩个字符串数组都是只出现一次就记录

class Solution {
public:
    int countWords(vector<string>& words1, vector<string>& words2) {
        unordered_map<string,int> words1_map,words2_map;    //定义两个字典
        for(const auto& word : words1){    //统计第一个字符串数组的字符串
            ++words1_map[word];
        }

        for(const auto& word : words2){    //统计第二个
            ++words2_map[word];
        }

        int count = 0;
        for(const auto& [word, num] : words1_map){    //每有一个字符串俩个数组都只出现一次就记录
            if(num == 1 && words2_map[word] == 1)
                ++count;
        }

        return count;
    }
};

相关推荐

  1. 2085.统计出现公共字符串

    2024-01-12 22:46:05       36 阅读
  2. 2085. 统计出现公共字符串

    2024-01-12 22:46:05       41 阅读
  3. LC 2085. 统计出现公共字符串

    2024-01-12 22:46:05       35 阅读
  4. 2085. 统计出现公共字符串

    2024-01-12 22:46:05       19 阅读
  5. 统计出现公共字符串

    2024-01-12 22:46:05       38 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-12 22:46:05       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-12 22:46:05       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-12 22:46:05       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-12 22:46:05       20 阅读

热门阅读

  1. Redis面试题10

    2024-01-12 22:46:05       33 阅读
  2. 解决大模型的幻觉问题:一种全新的视角

    2024-01-12 22:46:05       34 阅读
  3. 算法通关村第十二关-字符串基础题目

    2024-01-12 22:46:05       38 阅读
  4. 并发编程之ReentrantLock源码分析

    2024-01-12 22:46:05       35 阅读