aboutsummaryrefslogtreecommitdiff
path: root/intersection_2_array.py
diff options
context:
space:
mode:
Diffstat (limited to 'intersection_2_array.py')
-rw-r--r--intersection_2_array.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/intersection_2_array.py b/intersection_2_array.py
new file mode 100644
index 0000000..9c884bd
--- /dev/null
+++ b/intersection_2_array.py
@@ -0,0 +1,23 @@
+# 349. Intersection of Two Arrays
+
+"""
+given two integer arrays 'nums1' and 'nums2' return an array of their
+intersection. each element in the result must be unique and you may return
+the result in any order.
+"""
+
+
+class Solution(object):
+ def intersection(self, nums1, nums2):
+ """
+ :type nums1: List[int]
+ :type nums2: List[int]
+ :rtype: List[int]
+ """
+ return list(set(nums1).intersection(set(nums2)))
+
+
+if __name__ == "__main__":
+ obj = Solution()
+ print(obj.intersection(nums1=[1, 2, 2, 1], nums2=[2, 2]))
+ print(obj.intersection(nums1=[4, 9, 5], nums2=[9, 4, 9, 8, 4]))