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

原创 2016年05月30日 22:53:56

题目原文:
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

349. Intersection of Two Arrays [easy] (Python)

题目链接https://leetcode.com/problems/intersection-of-two-arrays/题目原文 Given two arrays, write a functi...

349. Intersection of Two Arrays I &&II (Java)

Given two arrays, write a function to compute their intersection.  Example:  Given nums1 = [1, 2, 2,...

[LeetCode-349] Intersection of Two Arrays(java)

Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2,...

LeetCode349 Intersection of Two Arrays

原题Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, ...

LeetCode之路:349. Intersection of Two Arrays

LeetCode之路:349. Intersection of Two Arrays 一、引言这是一道非常简单的题目,权当睡前的一点小练习,顺便看看他人的代码学点技巧了。题目信息如下: Given...

LeetCode笔记:349. Intersection of Two Arrays

找出两个数组中相同的数字(不能重复)

leetcode_349 Intersection of Two Arrays

题目分析:给定两个数组,求数组的交集。输出结果中的元素唯一,输出数组可以无序。 解题思路:1)对数组nums1进行排序;2)对数组nums2进行排序;3)遍历数组nums1和nums2中元素,并比较对...

<LeetCode OJ> 349 / 350 Intersection of Two Arrays(I / II)

Total Accepted: 3212 Total Submissions: 6814 Difficulty: Easy Given two arrays, write a functio...

LeetCode-349&350.Intersection of Two Arrays

https://leetcode.com/problems/intersection-of-two-arrays/ Given two arrays, write a function to co...

LeetCode - 349. Intersection of Two Arrays

这个题目中既然提到了distinct,duplicate相关的问题,那么自然可以想到使用Set。首先使用一个Set记录nums1中的所有元素,因为是Set,所以这样就消除了nums1中的重复元素,接着...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Easy-题目72:349. Intersection of Two Arrays(增补5)
举报原因:
原因补充:

(最多只允许输入30个字)