Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution(object):
- def intersect(self, nums1, nums2):
- """
- :type nums1: List[int]
- :type nums2: List[int]
- :rtype: List[int]
- """
- map = {}
- if len(nums2) > len(nums1):
- return Solution.intersect(self, nums2, nums1)
- for num in nums1:
- map[num] = map.get(num, 0) + 1
- i = 0
- for num in nums2:
- if map.get(num) > 0:
- nums1[i] = num
- map[num]= map.get(num) - 1
- i += 1
- return nums1[0 : i]
Advertisement
Add Comment
Please, Sign In to add comment