Leetcode <349.两个数组的交集>

题目:两个数组的交集

给定两个数组,编写一个函数来计算它们的交集python

示例

示例 1:
输入:nums1 = [1,2,2,1], nums2 = [2,2]
输出:[2]

示例 2
输入:nums1 = [4,9,5], nums2 = [9,4,9,8,4]
输出:[9,4]

说明

输出结果中的每一个元素必定是惟一的。 咱们能够不考虑输出结果的顺序。数组

代码

class Solution:
    def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
        return list(set(nums1)&set(nums2))

思路

python自带的set方法网络

来源:力扣(LeetCode)
连接:https://leetcode-cn.com/problems/design-circular-queue
著做权归领扣网络全部。商业转载请联系官方受权,非商业转载请注明出处。函数

相关文章
相关标签/搜索