[LeetCode]442. Find All Duplicates in an Array
来源:互联网 发布:电信机顶盒安装软件 编辑:程序博客网 时间:2024/06/05 05:32
https://leetcode.com/problems/find-all-duplicates-in-an-array/
由于要不用额外空间,因此还是染色法。一次遍历,把对应位置染成负数,如果本身已经是负数,说明之前已经出现过一次了,然后就加到结果里。
public class Solution { public List<Integer> findDuplicates(int[] nums) { List<Integer> res = new LinkedList<>(); if (nums == null || nums.length == 0) { return res; } for (int i = 0; i < nums.length; i++) { int index = Math.abs(nums[i]); if (nums[index - 1] < 0) { res.add(index); } nums[Math.abs(nums[i]) - 1] = -nums[Math.abs(nums[i]) - 1]; } return res; }}
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
- 汇编-学习笔记
- oracle如何实现全角和半角的切换
- 查看Android应用包名、Activity的几个方法
- 全面解析Hibernate框架--小白必看
- 使用javaScript动态加载Js文件和Css文件
- [LeetCode]442. Find All Duplicates in an Array
- 一次spinlock死锁故障的定位(太经典,收藏!)
- cocos2dx游戏开发之安装cocos2dx-3.13(一)
- cocos2d-x-3.12 设置sprite 图片大小
- 设置除法中断
- 服务器推送
- Android 源码目录 分析
- http://www.cnblogs.com/freeliver54/p/3725979.html
- 数组的输入输出 main函数形参