【LeetCode】Python实现-350. 两个数组的交集 II
2019-03-25 08:55
579 查看
给定两个数组,编写一个函数来计算它们的交集。
示例 1:
输入: nums1 = [1,2,2,1], nums2 = [2,2]
输出: [2,2]
示例 2:
输入: nums1 = [4,9,5], nums2 = [9,4,9,8,4]
输出: [4,9]
说明:
输出结果中每个元素出现的次数,应与元素在两个数组中出现的次数一致。
我们可以不考虑输出结果的顺序。
我的解答:
class Solution(object): def intersect(self, nums1, nums2): """ :type nums1: List[int] :type nums2: List[int] :rtype: List[int] """ s = [] for i in nums1: if i in nums2: s.append(i) nums2.remove(i) return s
相关文章推荐
- leetCode 349号题目详解 两个数组的交集 ,python3两种方式实现, 复杂度分别为O(n^2) 和 O(n)
- LeetCode--350. Intersection of Two Arrays II(两个数组的交集)Python
- LeetCode(初级算法)数组篇--两个数组的交集II c++
- [LeetCode] Intersection of Two Arrays II 两个数组的交集II
- Leetcode 两个数组的交集 II
- Leetcode:350. Intersection of Two Arrays II 求两个数组的交集
- [LeetCode]350. Intersection of Two Arrays II(求两个数组交集 II)
- [leetcode]两个数组的交集 II[javascript]
- leetcode-两个数组的交集 II
- LeetCode4.python实现:寻找两个有序数组中的中位数问题☆☆☆
- Python实现求两个数组交集的方法示例
- [easy]【leetcode】【java】 Intersection of Two Arrays II 两个数组的交集
- leetcode-350 Intersection of Two Arrays II 求两个数组的交集 面试见到了吗?
- leetcode 350. Intersection of Two Arrays II 两个数组的交集
- LeetCode:两个数组的交集 II
- Leetcode 350. Intersection of Two Arrays II 两个数组的交集 II
- [leetcode]两个数组的交集II
- leetcode 【 Unique Paths II 】 python 实现
- 【LeetCode-面试算法经典-Java实现】【081-Search in Rotated Sorted Array II(搜索旋转的排序数组)】
- python获得两个数组交集、并集、差集的方法