设计的很烂的一道题

 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. 天池新闻推荐比赛1:赛题理解+baseline

    天池新闻推荐比赛1:赛题理解+baseline 一.比赛信息 比赛链接: ​ https://tianchi.aliyun.com/competition/entrance/531842/inform ...

  2. oracle sql%notfound

    SQL%NOTFOUND 是一个布尔值.与最近的sql语句(update,insert,delete,select)发生交互,当最近的一条sql语句没有涉及任何行的时候,则返回true.否则返回fal ...

  3. java.util.UnknownFormatConversionException: Conversion = 'j' || Conversion = 'D' || Conversion = 'Y'

    执行内容: String a = "select * from j_question j where j.status = %s and j.title like '%java%'" ...

  4. android studio很好用的插件

  5. 第三十二章、使用splitDockWidget和tabifyDockWidget嵌套布局QDockWidget的PyQt人机对话案例

    专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 一.引言 在第<第三十一章.containers容器类部件QDo ...

  6. 第11.11节 Python正则表达式的指定重复次数匹配模式及元字符”{}”功能介绍

    在<第11.8节 Pytho正则表达式的重复匹配模式及元字符"?". "". "+"功能介绍>和<第11.10节 Pyth ...

  7. ios移动端 clipboard点击复制失效

    在使用clipboard.min.js插件库实现复制,android下没有问题,ios下无效! 原因:ios默认非点击标签没有点击效果 解决方法:需要给非点击标签加事件,比如在span,div或者p标 ...

  8. 什么时候使用transition?什么时候使用animation?

    不同点: 1. 触发条件不同.transition通常和hover等事件配合使用,由事件触发.animation则和gif动态图差不多,立即播放. 2. 循环. animation可以设定循环次数. ...

  9. 【题解】HDU4625 JZPTREE

    题目链接 题意 给定一棵 n 点的树,定义 \(dis(u,v)\) 为树上路径长度.对于每个点,定义 \(E_u=\sum_{v=1}^n dis(u,v)^k\) ,其中 k 为给定数. 求每个 ...

  10. 学习笔记:四边形不等式优化 DP

    定义 & 等价形式 四边形不等式是定义在整数集上的二元函数 \(w(x, y)\). 定义:对于任意 \(a \le b \le c \le d\),满足交叉小于等于包含(即 \(w(a, c ...