[Leetcode] Find All Duplicates in an Array
来源:互联网 发布:恩比德 知乎 编辑:程序博客网 时间:2024/05/21 10:43
描述
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]
给一个数组
分析
记录某元素
代码
class Solution {public: vector<int> findDuplicates(vector<int>& nums) { vector<int> res; for (int i = 0; i < nums.size(); i++) { if (nums[abs(nums[i]) - 1] < 0) res.push_back(abs(nums[i])); nums[abs(nums[i]) - 1] = - nums[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 (array)
- LeetCode-Find All Duplicates in an Array & Find All Numbers Disappeared 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)
- [C语言][LeetCode][442]Find All Duplicates in an Array
- [LeetCode]442. Find All Duplicates in an Array
- 【LeetCode-442】Find All Duplicates in an Array(C++)(
- leetcode 442 Find All Duplicates in an Array C++
- Leetcode 442. Find All Duplicates in an Array
- Android搜索框架
- 【JAVA学习】——Java虚拟机
- 算法提高 一元一次方程
- 100道动态规划——21 HDU 1559 最大子矩阵和 树状数组 最大连续子区间和
- HDU 1435 Stable Match(稳定婚姻问题)
- [Leetcode] Find All Duplicates in an Array
- C++重要知识点
- 半文不白的语言
- Unity 单例模式总结
- 每天一个 Linux 命令(6):rmdir 命令
- 单片机位运算操作
- 算法提高 选最大数
- leetcode 136. Single Number
- 如何理解Python关键字yield