leetcode 349[easy]---Intersection of Two Arrays
来源:互联网 发布:创世数据网 编辑:程序博客网 时间:2024/06/15 01:03
难度:easy
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.
思路:给定两个list,求两个list的交集,相同的数字只需要出现一次,不能重复。
方法1:用set的”可以求交集“和”set内的元素不能重复“这两个特性解题。
方法2:for循环找到存在list1但不存在于list2中,且不重复的数字。两个方法都很妙。
阅读全文
0 0
- leetcode 349[easy]---Intersection of Two Arrays
- Easy 349题 Intersection of Two Arrays
- Leetcode 349. Intersection of Two Arrays (Easy) (cpp)
- Leetcode 350. Intersection of Two Arrays II (Easy) (cpp)
- 349.leetcode Intersection of Two Arrays(easy)[数组 交集 set]
- LeetCode解题报告 349. Intersection of Two Arrays [easy]
- Leetcode-349 Intersection of Two Arrays
- leetcode 349 Intersection of Two Arrays C++
- LeetCode 349 Intersection of Two Arrays
- LeetCode-349&350.Intersection of Two Arrays
- LeetCode-349 Intersection of Two Arrays
- leetcode-Intersection of Two Arrays-349
- LeetCode 349 Intersection of Two Arrays
- LeetCode#349 Intersection of Two Arrays
- LeetCode(349)Intersection of Two Arrays
- [LeetCode]349 Intersection of Two Arrays
- [LeetCode-349] Intersection of Two Arrays(java)
- Leetcode 349 Intersection of Two Arrays
- unity中XML和JSON文档的解析
- Git使用提交代码遇到『Everything up-to-date』
- Extjs中使用Echarts(自适应)
- 随笔--工作一月
- 小游戏
- leetcode 349[easy]---Intersection of Two Arrays
- Java 大堆排序从0开始
- bootstrap 布局图片列表
- Android的CheckBox控件设置自定义图片
- 建设数据中心机房主要看这几点,否则被定为劣质机房!!!
- DUBBO常用xml配置总结与分类
- 3分钟学会sessionStorage用法
- 进程间通信方式----管道通信
- 第十四讲 适配器模式、内部类、递归算法、数据结构之链表、包装类、Eclipse开发环境设置