[leetcode]442. Find All Duplicates in an Array
来源:互联网 发布:淘宝客复制别人的商品 编辑:程序博客网 时间:2024/05/22 11:44
Question:
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appeartwice 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]
Answer:
public class Solution { public List<Integer> findDuplicates(int[] nums) { int[] aa = new int[nums.length+1]; //注意数组大小是n+1 List<Integer> result = new ArrayList<Integer>(); for(int i=0;i<nums.length;i++) { if(aa[nums[i]]!=0) { result.add(nums[i]); } else { aa[nums[i]] = 1; } } return result; }}
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
- Linux环境下的API和标准IO,并进行一系列的试验。
- 飘忽的产品日记17-02-12
- 从redis的hash结构中获取数据
- android底部菜单应用
- linux应用编程和网络编程-3.1.linux中的文件IO
- [leetcode]442. Find All Duplicates in an Array
- ScrollView嵌套ListView显示不完全、嵌套TextView不能滚动解决办法
- systemverilog语法(七)
- ueditor Uncaught ReferenceError: errorHandler is not defined解决办法
- 散列表解释
- [Leetcode] #143 Reorder List
- 区域学习简介
- MFC中自定义消息的实现
- Maven的作用通俗介绍