leetcode 442. Find All Duplicates in an Array 重复元素查找
来源:互联网 发布:线性时间选择算法c语言 编辑:程序博客网 时间:2024/06/03 04:07
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]
题意很简单,直接使用set遍历查询即可
代码如下:
#include <iostream>#include <vector>#include <map>#include <set>#include <queue>#include <stack>#include <string>#include <climits>#include <algorithm>#include <sstream>#include <functional>#include <bitset>using namespace std;class Solution {public: vector<int> findDuplicates(vector<int>& nums) { vector<int> res; set<int> ss; for (int a : nums) { if (ss.find(a) == ss.end()) ss.insert(a); else res.push_back(a); } return res; }};
阅读全文
0 0
- leetcode 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 找数组中的重复数字
- [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
- STM32 矩阵式LED的实现方式与思路
- Android Studio项目集成Unity详细教程
- ubuntu终端优化
- 【算法分析】Lucas–Kanade光流算法
- linux time命令
- leetcode 442. Find All Duplicates in an Array 重复元素查找
- Linux下使用git命令及github项目
- 20171208
- QT 局域网聊天 C/S
- 多地养老金告急,几十年后你可能没钱可领!
- android获取SIM卡信息和手机号码
- Spring Boot(四)——Mongodb
- 学习Maven日记-2
- 111