Leetcode-Intersection of Two Arrays-Python
来源:互联网 发布:按键精灵可以编vb 编辑:程序博客网 时间:2024/05/22 12:28
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].
Description
解题思路:
本来是想做关于排序的题目的,然后这道题的标签中就是含sort的,但我觉得用集合的方式会更简明些。
class Solution(object): def intersection(self, nums1, nums2): """ :type nums1: List[int] :type nums2: List[int] :rtype: List[int] """ set1 = set(nums1) set2 = set(nums2) return list(set1.intersection(set2))
tip:
set求交集函数返回的是set,因此需要通过list进行转换。
阅读全文
0 0
- [python][leetcode]Intersection of Two Arrays II
- leetcode 349. Intersection of Two Arrays python
- [leetcode: Python]349. Intersection of TWO Arrays
- Leetcode-Intersection of Two Arrays-Python
- [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
- maven依赖关系中Scope的作用
- 马路上的路灯
- 关于队列的个人见解
- docker存入和载出image
- 记录:我理解的B/S与C/S
- Leetcode-Intersection of Two Arrays-Python
- 全国职称计算机考试经验总结
- redis前端启动与后端启动
- 嵌入式linux 系统支持usb wifi BL-R8723BT1
- Prim模板
- .Net MVC&&datatables.js&&bootstrap做一个界面的CRUD有多简单
- web的基本攻击
- Hello World程序背后的故事解密(RtlUserThreadStart)
- neo4j使用教程(1) 从搭建neo4j网络服务开始