[leetcode349]Intersection of Two Arrays
设计的很烂的一道题
List<Integer> res = new ArrayList<>();
// int l1 = nums1.length;
// int l2 = nums2.length;
// int l = 0;
// while (l<l1&&l<l2)
// {
// if (nums1[l]==nums2[l])
// res.add(nums1[l]);
// l++;
// }
// int[] nums = new int[res.size()];
// for (int i = 0; i < nums.length; i++) {
// nums[i] = res.get(i);
// }
// return nums;
Set<Integer> set = new HashSet<>();
for (int a :
nums1) {
set.add(a);
}
for (int i = 0; i < nums2.length; i++) {
if (set.contains(nums2[i]))
res.add(nums2[i]);
}
set = new HashSet<>(res);
int[] nums = new int[set.size()];
int i =0;
for (int a :
set) {
nums[i] = a;
i++;
}
return nums;
[leetcode349]Intersection of Two Arrays的更多相关文章
- leetcode349—Intersection of Two Arrays
Given two arrays, write a function to compute their intersection. Example 1: Input: nums1 = [1,2,2,1 ...
- leetcode349 350 Intersection of Two Arrays & II
""" Intersection of Two Arrays Given two arrays, write a function to compute their in ...
- [LeetCode] Intersection of Two Arrays II 两个数组相交之二
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- [LeetCode] Intersection of Two Arrays 两个数组相交
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- LeetCode Intersection of Two Arrays
原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays/ 题目: Given two arrays, write a func ...
- LeetCode Intersection of Two Arrays II
原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays-ii/ 题目: Given two arrays, write a f ...
- [LintCode] Intersection of Two Arrays II 两个数组相交之二
Given two arrays, write a function to compute their intersection.Notice Each element in the result s ...
- [LintCode] Intersection of Two Arrays 两个数组相交
Given two arrays, write a function to compute their intersection.Notice Each element in the result m ...
- Intersection of Two Arrays | & ||
Intersection of Two Arrays Given two arrays, write a function to compute their intersection. Example ...
随机推荐
- JZOJ2020年8月14日提高组反思
JZOJ2020年8月14日提高组反思 T1 看到题 一脸:我是谁,我在哪,我要干啥 看到字符串凉一半 还有查询修改 想到线段树但不会建模 暴力安排 T2 一开始觉得:水题 然后啪啪打脸 空间小,数据 ...
- celery使用-win10和linux
win10启动方式 celery -A celery_tasks.main worker -l debug -P eventlet linux启动方式 /usr/local/bin/celery ce ...
- 第8.1节 Python类的构造方法__init__深入剖析:语法释义
一. 引言 凡是面向对象设计的语言,在类实例化时都有构造方法,很多语言的构造方法名与类名一致,Python中类的构造方法比较特殊,必须是__init__特殊方法. 二. 语法释义 1. ...
- Python基础教程目录
老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python部分代码样例 老猿Python重难点知识博文汇总 老猿Python博客地址 第1章 Python学习环境构建目 ...
- SELECT 1,2,3...的含义及其在SQL注入中的用法
首先,select 之后可以接一串数字:1,2,3-只是一个例子,这串数字并不一定要按从小到大排列,也不一定从1开始,这串数字的值和顺序是任意的,甚至可以是重复的,如:11,465,7461,35 或 ...
- flask注册蓝图报错
记录下这个我找了两天的坑... take no arguments() 这两天一直学习flask的时候,我把注册的蓝图,写成注册的form表单的 举个栗子 class TetsView(view.Me ...
- P4317 花神的数论题,关于luogu题解粉兔做法的理解
link 题意 设 \(\text{sum}(i)\) 表示 \(i\) 的二进制表示中 \(1\) 的个数.给出一个正整数 \(N\) ,求 \(\prod_{i=1}^{N}\text{sum}( ...
- Java集合源码分析(六)——ConcurrentHashMap
目录 简介 源码分析 父类 接口 字段 内部类 1.链表节点结构 2.树根结构 3.树节点结构 方法 1.构造方法 2.基本并发方法 3.初始化表数组的操作 4.修改添加元素 5.统计元素数量 6.扩 ...
- 博流BL602&BL604开发板介绍
在2020松山湖论坛上,博流智能科技(南京)有限公司销售副总裁刘占领介绍了基于RISC-V核的低功耗.高可靠Wi-Fi+BLE二合一SoC芯片BL602.主要应用领域包括人工智能与工业互联网,特别是电 ...
- 哔哩哔哩批量采集器(支持windows和mac)
链接:https://pan.baidu.com/s/1jW2ea0Cl1xL5xN9DuB8Fcw 密码:klyw