Skip to content

Commit 96dbc2d

Browse files
committed
Create 2085-CountCommonWordsWithOneOccurence.cpp
1 parent 015789f commit 96dbc2d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
int countWords(vector<string>& words1, vector<string>& words2) {
4+
std::map<std::string, int> a, b;
5+
for(int p = 0; p < words1.size(); p++){++a[words1[p]];}
6+
for(int p = 0; p < words2.size(); p++){++b[words2[p]];}
7+
int cnt(0);
8+
for(std::map<std::string, int>::iterator it = a.begin(); it != a.end(); it++){
9+
if(it->second > 1){continue;}
10+
std::string key = it->first;
11+
if(b.count(key) && b[key] == 1){++cnt;}
12+
}
13+
14+
return cnt;
15+
}
16+
};

0 commit comments

Comments
 (0)