349. Intersection of Two Arrays

種類 : hash table
難度 : easy
題目 : 349. Intersection of Two Arrays

思維邏輯

  1. 使用set篩出重複值
  2. 取兩個set集合,並轉成list

解法

1
2
3
4
class Solution:
def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
set1, set2 = set(nums1), set(nums2)
return list(set1 & set2)

時間複雜度: O(1)
空間複雜度: O(1)

難點

最佳解法

此為最佳解法