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
Using hash map to opimize the algorithm o(N). Instead of using sorting. It takes O(NlogN). But my solution takes require more space then sorting approach.
3
+
Approach
4
+
My first thought is using a "Hash_map" to store the elements of 1 array and corresponding frequency into hash map.
5
+
Add the elements of "nums1" into map with corresponding frequency.
6
+
Iterate throught each element of "nums2". If frequency of the element stored in hash map greater than 0. We add this element into "res" and decrease the frequency of this element.
0 commit comments