• 46.2%

https://leetcode.com/problems/intersection-of-two-arrays/?tab=Description

Given two arrays, write a function to compute their intersection.

Note:

• Each element in the result must be unique.
• The result can be in any order.

12ms, 42.46%, June.5th, 2016

cpp

https://discuss.leetcode.com/topic/45846/small-c-solution

https://leetcode.com/discuss/103224/my-c-solution-with-sort

12ms, 42.46%, June.5th, 2016

https://leetcode.com/discuss/103365/8ms-concise-c-using-unordered_set

16ms, 17.41%, June.5th, 2016

8ms concise C++ using unordered_set

python

Solution Mine:

52ms, 60 / 60, 76.78%, June.5th, 2016

Solution 1:

https://leetcode.com/discuss/103709/python-code-3-lines-using-set

June.5th, 2016

Solution 2:

https://leetcode.com/discuss/103709/python-code-3-lines-using-set

https://discuss.leetcode.com/topic/45727/four-python-solutions-with-simple-explanation

Solution 1:

use set operation in python, one-line solution.

Solution 2:

brute-force searching, search each element of the first list in the second list. (to be more efficient, you can sort the second list and use binary search to accelerate)

``````return res
``````

Solution 3:

use dict/hashmap to record all nums appeared in the first list, and then check if there are nums in the second list have appeared in the map.

Solution 4:

sort the two list, and use two pointer to search in the lists to find common elements.

java

https://discuss.leetcode.com/topic/45685/three-java-solutions

7ms, 34.67%, June.5th, 2016

Use two hash sets

Time complexity: O(n)

https://discuss.leetcode.com/topic/45685/three-java-solutions

Sort both arrays, use two pointers

Time complexity: O(nlogn)

https://discuss.leetcode.com/topic/45685/three-java-solutions

Binary search

Time complexity: O(nlogn)