350. Intersection of Two Arrays II ¶
Approach 1: Hash Table¶
- Time: $O(m + n)$
- Space: $O(\min(m, n))$
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Approach 2: Two Pointers¶
- Time: $O(m\log m + n\log n)$
- Space: $O(\min(m, n))$
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
Approach 3: Binary Search¶
- Time: $O(\min(m\log n, n\log m))$
- Space: $O(\min(m, n))$
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|