leetcode之 Intersection of Two Arrays
来源:互联网 发布:万国数据公司怎么样 编辑:程序博客网 时间:2024/05/08 16:47
这题比较简单,是求2个不同list的公共部分。要求是元素必须是唯一的。先将2个list去重,然后从少的list开始循环求解。
class Solution(object): def intersection(self, nums1, nums2): """ :type nums1: List[int] :type nums2: List[int] :rtype: List[int] """ if nums1 == [] or nums2 == []: return [] result = [] nums1 = set(nums1) nums2 = set(nums2) if len(nums1) <= len(nums2): for i in nums1: if i in nums2: result.append(i) else: for i in nums2: if i in nums1: result.append(i) return result
0 0
- leetcode之 Intersection of Two Arrays
- leetcode之Intersection of Two Arrays II
- LeetCode之Intersection of Two Arrays
- Leetcode 之 Intersection of Two Arrays II
- Leetcode之Intersection of Two Arrays 问题
- [LeetCode] Intersection of Two Arrays
- LeetCode Intersection of Two Arrays
- LeetCode:Intersection of Two Arrays
- 【leetcode】Intersection of Two Arrays
- leetcode Intersection of Two Arrays
- 【leetcode】Intersection of Two Arrays
- leetcode:Intersection of Two Arrays
- [Leetcode]Intersection of Two Arrays
- LeetCode:Intersection of Two Arrays
- LeetCode: Intersection of Two Arrays
- leetcode ----Intersection of Two Arrays
- LeetCode Intersection of Two Arrays
- [Leetcode] Intersection of Two Arrays
- 回望来时的路:构建之法东北师大站 2016春季学期
- 《数值分析》期末考试a
- 《数值分析》期末考试试卷(B卷)
- leetcode之Top K Frequent Elements
- leetcode 2. Add Two Numbers
- leetcode之 Intersection of Two Arrays
- Ubuntu 安装jetty
- 访问远程Redis服务。Connect to Remote Redis Server
- LeetCode 42. Trapping Rain Water
- Java练习:java.lang.Throwable
- 创业吧,创业!【2016-06-09】
- 使用Listagg分析函数优化wmsys.wm_concat
- 开源自定义控件
- android控件篇:ViewPager+Fragment+GridView的使用(与AndroidQuery框架结合)