leetcode笔记10 Intersection of Two Arrays(求交集)

问题描述:

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.

my answer:

思路:

遍历nums1里的元素,看nums2里是否存在,如果存在且没有在num里出现过,则添加到num,最后返回num

重点问题:

1 忘记考虑nums1为None的情况

2 在第二个if 下使用set(num)总是报错,还没有明白为什么 

原文地址:https://www.cnblogs.com/qicaide/p/6021965.html