[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月7日提高组反思
JZOJ2020年8月7日提高组反思 T1 暴力枚举 枚举起点和\(p\) 然后就 过了?! 根据本人不严谨的推算 时间复杂度\(O(\dfrac{n^7}{4})\) 数据太水就过去了QAQ T2 ...
- 在 CentOS 7 安装 RabbitMQ
一.安装 Erlang RabbitMQ 是使用 Erlang 开发的,所以需要首先安装 Erlang,本文安装其最新版本 添加 repo 文件: sudo vim /etc/yum.repos.d/ ...
- 老猿学5G扫盲贴:3GPP规范中与计费相关的主要规范文档列表及下载链接
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 老猿学5G博文目录 在<老猿学5G扫盲贴:3GPP规范中部分与计 ...
- 第12.1节 Python os模块导览
os 模块提供了许多与操作系统交互的函数,一定要使用 import os 而不是 from os import * ,这将避免内建的 open() 函数被 os.open() 隐式替换掉,它们的使用方 ...
- PyQt(Python+Qt)学习随笔:Qt Designer中QAbstractButton派生按钮部件的shortcut 属性
shortcut 属性保存与按钮关联的快捷键.可以使用shortcut()和setShortcut(QKeySequence)访问和设置该属性. 关于这个属性官网介绍的不多,经老猿实际验证,它与tex ...
- HTTP助记
1** 信息,服务器收到请求,需要请求者继续执行操作 100 continue 继续,客户端应继续请求 101 swithching protocls 切换协议,服务器根据客户端的请求切换协议.只能切 ...
- CTFD平台部署自制题目指北(灌题)
给实验室同学搭建的CTFD平台用于内部训练和CTF的校赛,为了循序渐进当然是先内部出一些简单入门的题目,但是网上大部分关于CTFD平台的都只是部署,而关于题目放置的内容却很少,虽然这个过程比较简单,但 ...
- flask中的重定向,渲染,反转视图函数
在学习flask中,重定向,渲染,反转老是不怎么明白,今天明白了其中的点了,来给大家分享下 rend_templete()这个函数就是一个渲染的作用,渲染html的东西. url_for是反转视图函数 ...
- Ambari HDP集群搭建全攻略
世界上最快的捷径,就是脚踏实地,本文已收录[架构技术专栏]关注这个喜欢分享的地方. 最近因为工作上需要重新用Ambari搭了一套Hadoop集群,就把搭建的过程记录了下来,也希望给有同样需求的小伙伴们 ...
- Ubuntu18开机执行shell命令
1.打开shell终端,输入 sudo vi /etc/rc.local 2.在编辑器里面输入自己要启动的脚本,特别强调:脚本(程序)要有可执行权限 #!/bin/bash echo "ru ...