You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/2000-2099/2085.Count Common Words With One Occurrence/README_EN.md
+52-21
Original file line number
Diff line number
Diff line change
@@ -47,6 +47,12 @@ Thus, there are 2 strings that appear exactly once in each of the two arrays.
47
47
48
48
## Solutions
49
49
50
+
**Solution 1: Hash Table + Counting**
51
+
52
+
We can use two hash tables, $cnt1$ and $cnt2$, to count the occurrences of each string in the two string arrays respectively. Then, we traverse one of the hash tables. If a string appears once in the other hash table and also appears once in the current hash table, we increment the answer by one.
53
+
54
+
The time complexity is $O(n + m)$, and the space complexity is $O(n + m)$. Where $n$ and $m$ are the lengths of the two string arrays respectively.
0 commit comments