old_contents: # Time:  O(nlogn)
  # Space: O(1)
  
  # Given two arrays, write a function to compute their intersection.
  #
  # Example:
  # Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].
  #
  # Note:
  # Each element in the result must be unique.
  # The result can be in any order.
  
  class Solution(object):
      def intersection(self, nums1, nums2):
          """
          :type nums1: List[int]
          :type nums2: List[int]
          :rtype: List[int]
          """
          nums1.sort(), nums2.sort()
          res = []
          
          it1, it2 = 0, 0
          while it1 < len(nums1) and it2 < len(nums2):
              if nums1[it1] < nums2[it2]:
                  it1 += 1
              elif nums1[it1] > nums2[it2]:
                  it2 += 1
              else:
                  if not res or res[-1] != nums1[it1]:
                      res += nums1[it1],
                  it1 += 1
                  it2 += 1
          
          return res
  
new_contents: # Time:  O(m + n)
  # Space: O(min(m, n))
  
  # Given two arrays, write a function to compute their intersection.
  #
  # Example:
  # Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].
  #
  # Note:
  # Each element in the result must be unique.
  # The result can be in any order.
  
  class Solution(object):
      def intersection(self, nums1, nums2):
          """
          :type nums1: List[int]
          :type nums2: List[int]
          :rtype: List[int]
          """
          if len(nums1) > len(nums2):
              return self.intersection(nums2, nums1)
    
          lookup = set()
          for i in nums1:
              lookup.add(i)
  
          res = []
          for i in nums2:
              if i in lookup:
                  res += i,
                  lookup.discard(i)
  
          return res
  
  
  # Time:  O(nlogn)
  # Space: O(1)
  class Solution2(object):
      def intersection(self, nums1, nums2):
          """
          :type nums1: List[int]
          :type nums2: List[int]
          :rtype: List[int]
          """
          nums1.sort(), nums2.sort()
          res = []
          
          it1, it2 = 0, 0
          while it1 < len(nums1) and it2 < len(nums2):
              if nums1[it1] < nums2[it2]:
                  it1 += 1
              elif nums1[it1] > nums2[it2]:
                  it2 += 1
              else:
                  if not res or res[-1] != nums1[it1]:
                      res += nums1[it1],
                  it1 += 1
                  it2 += 1
          
          return res
  
subject: Update intersection-of-two-arrays.py