【LeetCode】442. Find All Duplicates in an Array
来源:互联网 发布:2017天猫双11销售数据 编辑:程序博客网 时间:2024/06/16 23:01
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.
Find all the elements that appear twice in this array.
Could you do it without extra space and in O(n) runtime?
Example:
Input:[4,3,2,7,8,2,3,1]Output:[2,3]
很简单的一个题目,要求了事件复杂度是o(n)。
用hash表来做。
/** * @param {number[]} nums * @return {number[]} */var findDuplicates = function(nums) { var arr=[]; var ret=[]; for(var i=nums.length-1;i>=0;i--){ if(arr[nums[i]]){ ret.push(nums[i]); }else{ arr[nums[i]]=true; } } return ret;};
阅读全文
0 0
- [LeetCode]Find All Duplicates in an Array
- LeetCode Find All Duplicates in an Array
- Leetcode Find All Duplicates in an Array
- [Leetcode] Find All Duplicates in an Array
- leetCode-Find All Duplicates in an Array
- [leetcode] 442. Find All Duplicates in an Array
- LeetCode 442. Find All Duplicates in an Array
- leetcode:442. Find All Duplicates in an Array
- 442. Find All Duplicates in an Array(LeetCode)
- <leetcode>442. Find All Duplicates in an Array
- [leetcode]442. Find All Duplicates in an Array(java)
- [LeetCode]442. Find All Duplicates in an Array
- Leetcode 442. Find All Duplicates in an Array
- LeetCode笔记:442. Find All Duplicates in an Array
- 【LeetCode】 442. Find All Duplicates in an Array
- [leetcode]442. Find All Duplicates in an Array
- Leetcode 442. Find All Duplicates in an Array
- LeetCode 442. Find All Duplicates in an Array
- maven导入已有jar包
- 读书笔记总结(链接)
- java线程中断的理解
- 实现生产组和消费者的机制,利用共享内存实现文件的打开和读写操作,PV操作。
- 线程池详解
- 【LeetCode】442. Find All Duplicates in an Array
- 主流的 骨骼蒙皮动画 顶点变换方式的一个细节的思考
- QTransform Qt坐标转换
- H5---面试题八
- mAP,精确率,召回率,查重率,查准率的定义
- Linux操作系统上安装Java-学习笔记
- 68. Text Justification
- WPF UI Automation
- 序列化DataTable