2085.cpp (392B)
1 class Solution { 2 public: 3 int countWords(vector<string> &words1, vector<string> &words2) { 4 unordered_map<string, int> um1, um2; 5 6 for (auto &t : words1) 7 um1[t]++; 8 for (auto &t : words2) 9 um2[t]++; 10 11 int count = 0; 12 for (auto &[str, cnt] : um1) 13 if (cnt == 1 && um2[str] == 1) count++; 14 return count; 15 } 16 };