leetcode349
来源:互联网 发布:管家婆软件使用感想 编辑:程序博客网 时间:2024/05/24 06:34
349 easy Intersection of Two Arrays
*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.*
我是这样写的:
class Solution(object): def intersection(self, nums1, nums2): """ :type nums1: List[int] :type nums2: List[int] :rtype: List[int] """ l=[] for num in nums1: if num in nums2 and num not in l: l.append(num) return l
然后在Discuss中看到有人居然只用了一句话!!!(好��)
return [x for x in set(nums1) if x in set(nums2)]
总结点呢 就是:set可以除重复 这要写巧妙的避开了是否重复的判断
;还有就是使用列表生成简单了很多。
0 0
- leetcode349
- leetcode349&350
- leetcode349: Intersection of Two Arrays
- Leetcode349. Intersection of Two Arrays
- Leetcode349. Intersection of Two Arrays
- Leetcode349. Intersection of Two Arrays
- LeetCode349. Intersection of Two Arrays
- LeetCode349 Intersection of Two Arrays
- leetcode349~Intersection of Two Arrays
- leetcode349. Intersection of Two Arrays
- leetcode349. Intersection of Two Arrays
- 算法刷题系列(1)leetcode349
- LeetCode349. Intersection of Two Arrays我的做法
- Leetcode349 - Intersection of Two Arrays(two pointers)
- Android 避免APP启动闪黑屏的解决办法(Theme和Style)
- Ext.data.Store动态修改url
- UML关系(泛化,实现,依赖,关联(聚合,组合))
- Extjs5....布局,分页栏不不显示在最底端解决方法!
- vs中debug和relsese版本的区别
- leetcode349
- U盘ext3格式化
- MySQL数据库如何解决大数据量存储问题
- Linux 下载 更新 google 浏览器 chrome
- spring mvc DispatcherServlet作用
- 关于恢复出厂设置的说明
- MapReduce:详解Shuffle过程
- viewpager+fragment
- hihocoder 1077 线段树 java实现