By Long Luo

Here shows 2 approaches for this problem: Sorting with Two Pointers and HashMap.

# Sorting with Two Pointers

Sorting the two arrays first, then find the same elements.

## Analysis

• Time Complexity: $O(mlogm + nlogn)$
• Space Complexity: $O(min(m+n))$

# HashMap

Choose the array which is less and use $\textit{HashMap}$ to store the elements of the array.

## Analysis

• Time Complexity: $O(m+n)$.
• Space Complexity: $O(min(m+n))$.

All suggestions are welcome.
If you have any query or suggestion please comment below.
Please upvote👍 if you like💗 it. Thank you:-)

Explore More Leetcode Solutions. 😉😃💗