美文网首页
349. Intersection of Two Arrays

349. Intersection of Two Arrays

作者: a_void | 来源:发表于2016-09-16 15:55 被阅读0次

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]
        """
        return list(set(nums1) & set(nums2))

相关文章

网友评论

      本文标题:349. Intersection of Two Arrays

      本文链接:https://www.haomeiwen.com/subject/hjliettx.html