349. Intersection of Two Arrays
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.
代码如下:
- public class Solution {
- public int[] intersection(int[] nums1, int[] nums2) {
- ArrayList<Integer> list=new ArrayList<>();
- for(int i=0;i<nums1.length;i++)
- {
- for(int j=0;j<nums2.length;j++)
- {
- if(nums1[i]==nums2[j])
- {
- if(!list.contains(nums1[i]))
- list.add(nums1[i]);
- }
- }
- }
- int[] result=new int[list.size()];
- for(int i=0;i<list.size();i++)
- result[i]=list.get(i);
- return result;
- }
- }
349. Intersection of Two Arrays的更多相关文章
- [LeetCode] 349 Intersection of Two Arrays && 350 Intersection of Two Arrays II
这两道题都是求两个数组之间的重复元素,因此把它们放在一起. 原题地址: 349 Intersection of Two Arrays :https://leetcode.com/problems/in ...
- LeetCode Javascript实现 283. Move Zeroes 349. Intersection of Two Arrays 237. Delete Node in a Linked List
283. Move Zeroes var moveZeroes = function(nums) { var num1=0,num2=1; while(num1!=num2){ nums.forEac ...
- [LeetCode] 349. Intersection of Two Arrays 两个数组相交
Given two arrays, write a function to compute their intersection. Example 1: Input: nums1 = [1,2,2,1 ...
- LeetCode 349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- 15. leetcode 349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1 ...
- 【leetcode】349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1 ...
- Add to List 349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- 【一天一道LeetCode】#349. Intersection of Two Arrays
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given t ...
- LeetCode 349 Intersection of Two Arrays 解题报告
题目要求 Given two arrays, write a function to compute their intersection. 题目分析及思路 给定两个数组,要求得到它们之中共同拥有的元 ...
随机推荐
- 基于MVC模式的应用框架之struts
1.struts开发步骤 引入struts的jar包: 在web.xml中引入struts的核心功能,配置struts核心过滤器:(如果项目中用到了其他过滤器,要放在struts过滤器之前,否则会失效 ...
- 弹框工作区(dialog)
弹出窗口分为普通弹出窗口和模态弹出窗口,普通弹出窗口可以铜鼓taskBar组件进行最小化等操作.弹出的窗口的DOM结构会放入主页面的body中,结构如下: <div class="bj ...
- SharePoint 2013 Nintex Workflow 工作流帮助(四)
博客地址 http://blog.csdn.net/foxdave 接上篇点击打开链接 我们来看下一个配置标签Ribbon Option: Task Notification(用于配置分配任务时的提醒 ...
- Windows Azure上搭建SSTP VPN
一.服务器设置 首先,从0开始,你需要创建一个新的VM.我选择Windows Server 2012 R2,所有步骤和创建普通VM都一样,但最后在防火墙设置里一定要打开TCP 443端口: 创建完成后 ...
- C# MP3文件属性读取
using (TempFile tempFile = new TempFile()) { using (FileStream fs = new FileStream(tempFile.FileName ...
- linux下磁盘进行分区、文件系统创建、挂载和卸载
任务的原因:由于,刚购买来的服务器需要将磁盘挂载到操作系统上,为了挂载磁盘首先要对磁盘进行分区,然后进行文件系统的创建,最后将磁盘挂载到操作系统上的某个目录. MBR(Master Boot Reco ...
- 详解模块定义(.def)文件
一个完整的Windows应用程序(C++程序)通常由五种类型的文件组成:源程序文件,头文件,资源描述文件,项目文件,模块定义文件.本文主要讲解模块定义文件. 模块定义 (.def)文件为链接器提供有关 ...
- nginx添加未编译安装模块
链接:http://taokey.blog.51cto.com/4633273/1318719
- RFIDler:一款定义RFID的读、写、仿真器的开源软件
很多类似于RFID这样的技术看起来都很神秘,实际上他是依赖于很多物理学原理的,比如”电磁感应原理”.是的,这些现象产生的各种信号足以令人发狂,看完这些模拟模拟信号后,我忽然发现二进制信息多么干净美丽. ...
- HDOJ-三部曲-多重背包-1014-Cash Machine
通过这道题我基本了解了利用二进制对多重背包问题进行优化的思想. Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submiss ...