G2A Many GEOs
SHARE
TWEET

Intersection of Two Arrays II

aero2146 Apr 10th, 2020 127 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution:
  2.     def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:
  3.         num_freq = dict()
  4.         res = []
  5.        
  6.         for num in nums1:
  7.             if num in num_freq:
  8.                 num_freq[num] += 1
  9.             else:
  10.                 num_freq[num] = 1
  11.        
  12.         for num in nums2:
  13.             if num in num_freq and num_freq[num] != 0:
  14.                 num_freq[num] -= 1
  15.                 res.append(num)
  16.        
  17.         return res
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top