【数组】Leetcode编程题解:442. Find All Duplicates in an Array
来源:互联网 发布:散热分析中文软件 编辑:程序博客网 时间:2024/06/05 10:50
题目: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?
样例:
Input:
[4,3,2,7,8,2,3,1]
Output:
[2,3]
这道题其实是上道题的改版,难度不大
提交代码:
# include < cstring >
class Solution {
public:
vector findDuplicates(vector& nums) {
int len = nums.size();
int result[len + 1];
memset(result, 0, sizeof(result));
for(int i = 0; i < len; i++) {
result[nums[i]]++;
}
vector ans;
for(int i = 0; i <= len; i++) {
if(result[i] == 2)
ans.push_back(i);
}
return ans;
}
};
- 【数组】Leetcode编程题解:442. Find All Duplicates in an Array
- Find All Duplicates in an Array 题解
- LeeCode 442. 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-Find All Duplicates in an Array
- 题解——Leetcode 442. Find All Duplicates in an Array 难度:Medium
- leetcode题解-75. Sort Colors && 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
- 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
- Android 编程下 Touch 事件的分发和消费机制
- 安卓界面组件---文版框
- H5_2_表单
- Target runtime Tomcat v7.0 is not defined.
- 51nod:1384 全排列(dfs||c++函数)
- 【数组】Leetcode编程题解:442. Find All Duplicates in an Array
- jQuery绑定键盘压下抬起事件
- 文章标题
- RegExp正则表达式(简单入门)
- composer的安装及配置
- 前端总结·基础篇·CSS(一)布局
- java实现网上在线支付--04_编写易宝支付的客户端加密工具类
- 重装系统win7让你惊呆下巴
- 数据安全之MD5、SHA-1、CRC32区别