Easy-题目72:349. Intersection of Two Arrays(增补5)

题目原文:
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.
题目大意:
给出两个数组,求他们的交集,相同元素只出现一次。
题目分析:
用python的set最好做。
源码:(language:python)

class Solution(object):
    def intersection(self, nums1, nums2):
        return list(set(nums1) & set(nums2))

成绩:
60ms

阅读更多
版权声明:完整版Leetcode题解请出门左转https://github.com/cmershen1/leetcode/tree/master/docs https://blog.csdn.net/cmershen/article/details/51541897
个人分类: Leetcode
上一篇Easy-题目71:345. Reverse Vowels of a String(增补4)
下一篇Easy-题目73:350. Intersection of Two Arrays II(增补6)
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭