设计的很烂的一道题

 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的更多相关文章

  1. leetcode349—Intersection of Two Arrays

    Given two arrays, write a function to compute their intersection. Example 1: Input: nums1 = [1,2,2,1 ...

  2. leetcode349 350 Intersection of Two Arrays & II

    """ Intersection of Two Arrays Given two arrays, write a function to compute their in ...

  3. [LeetCode] Intersection of Two Arrays II 两个数组相交之二

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

  4. [LeetCode] Intersection of Two Arrays 两个数组相交

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

  5. LeetCode Intersection of Two Arrays

    原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays/ 题目: Given two arrays, write a func ...

  6. LeetCode Intersection of Two Arrays II

    原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays-ii/ 题目: Given two arrays, write a f ...

  7. [LintCode] Intersection of Two Arrays II 两个数组相交之二

    Given two arrays, write a function to compute their intersection.Notice Each element in the result s ...

  8. [LintCode] Intersection of Two Arrays 两个数组相交

    Given two arrays, write a function to compute their intersection.Notice Each element in the result m ...

  9. Intersection of Two Arrays | & ||

    Intersection of Two Arrays Given two arrays, write a function to compute their intersection. Example ...

随机推荐

  1. LeetCode 037 Sudoku Solver

    题目要求:Sudoku Solver Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells ...

  2. PADS经验总结

    PADS经验总结 1. 快捷键z+数字,能够快速查看相应层:直接z,会显示所有层: 2. 快捷键l+数字,在走线时能够快速切换层: 3. setup->design Rules能设置线宽,DRC ...

  3. Python to Exe By Install PyInstaller on Win7-64bit

    本文主要记录为史振华在尝试转换PY文件为EXE文件过程中各种疑惑和最终解决方法,尝试了PYTHON 2.7/3.5/3.6及其相关依赖pywin32-222.win32/pywin32-222.win ...

  4. IdentityServer4系列 | 简化模式

    一.前言 从上一篇关于资源密码凭证模式中,通过使用client_id和client_secret以及用户名密码通过应用Client(客户端)直接获取,从而请求获取受保护的资源,但是这种方式存在clie ...

  5. 全文检索django-haystack+jieba+whoosh

    全文检索里的组件简介 1.什么是haystack? 1. haystack是django的开源搜索框架,该框架支持Solr,Elasticsearch,Whoosh, *Xapian*搜索引擎,不用更 ...

  6. 第7.6节 Python中类的继承机制详述

    在本章第一节,介绍了面向对象程序设计的三个特征:封装.继承和多态,前面章节重点介绍了封装和多态,由于Python语言是多态语言,对象的类型不再由继承等方式决定,而由实际运行时所表现出的具体行为来决定, ...

  7. 转:Python常见字符编码及其之间的转换

    参考:Python常见字符编码 + Python常见字符编码间的转换 一.Python常见字符编码 字符编码的常用种类介绍 第一种:ASCII码 ASCII(American Standard Cod ...

  8. PyQt(Python+Qt)学习随笔:QTableWidget设置项的setItem方法

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 QTableWidget表格部件中setItem用于在表格部件QTableWidget创建后,设定指 ...

  9. Python接口测试-使用requests模块发送GET请求

    本篇主要记录下使用python的requests模块发送GET请求的实现代码. 向服务器发送get请求:无参数时:r = requests.get(url)带params时:r = requests. ...

  10. 测试与发布( Alpha版本 )

    THE BUG 团队 杨梓琦 温海源 李华 陈杰才 郑堡恩 钟明康 软件说明 本软件用MYSQL数据库保存所有的数据内容,因此可以通过查询数据库查询功能是否正常进行. 测试过程 在测试过程中,左右两张 ...