[LeetCode]442. Find All Duplicates in an Array
来源:互联网 发布:2016年云计算政策 编辑:程序博客网 时间:2024/06/06 18:44
[LeetCode]442. Find All Duplicates in an Array
题目描述
思路
出现数字的范围和数组长度一致,并且只重复出现两次,可以用位置标记,当这个位置被访问一次的时候,将位子上的数字置负,再次访问的时候,就将该表示该位置的数存入结果数组。
代码
class Solution {public: vector<int> findDuplicates(vector<int>& nums) { vector<int> res; for (int i = 0; i < nums.size(); ++i){ int flag = abs(nums[i]) - 1; if (nums[flag] > 0){ nums[flag] = -nums[flag]; } else { res.push_back(flag + 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
- python bar函数
- Calculator Conundrun UVA 11549
- linux shell脚本知识点总结
- C++30道常见面试题
- 怎么防止网站图片被盗链?
- [LeetCode]442. Find All Duplicates in an Array
- 【Unity3d】导入包材质缺失的补救方法(纯转载)
- 【学习写测试用例2】如何测试微信朋友圈对你的状态进行点赞
- Linux命令(一)
- C语言
- PL/SQL 学习 第一节
- python往mysql中插入数据时,中文乱码的问题
- TextView的跑马灯效果
- 三表关联一对多时sum函数的使用 demo