🔥 Burn Fat Fast. Discover How! 💪

#N2085. Count Common Words With One Occurrence problem link # | Leetcode in Java && MySQL

#N2085. Count Common Words With One Occurrence
problem link

#solution
class Solution {
public int countWords(String[] words1, String[] words2) {
int count=0;

Map map1 = new HashMap<>();
Map map2 = new HashMap<>();
for(String word: words1)
map1.put(word, map1.getOrDefault(word, 0) +1);

for(String word: words2)
map2.put(word, map2.getOrDefault(word, 0) +1);

for (String word: words1)
if(map1.get(word) == 1 && map2.getOrDefault(word, 0) == 1) count++;

return count;
}
}