leetcode442
来源:互联网 发布:hex 编辑器 c语言 编辑:程序博客网 时间:2024/05/02 04:39
1、Find All Duplicates in an Array
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) { unordered_map<int,int> num; vector<int> result; for(auto i:nums) ++num[i]; for(auto i=num.begin();i!=num.end();i++){ if((*i).second>1) result.push_back((*i).first); } return result; }};
感觉比较简单粗暴QvQ
0 0
- leetcode442
- 第四周作业2(LeetCode442)
- Leetcode442. Find All Duplicates in an Array
- leetcode442. Find All Duplicates in an Array
- leetcode442 Find All Duplicates in an Array
- Leetcode442. Find All Duplicates in an Array
- Leetcode442. 通过哈希表找出数组重复元素
- leetcode442 Find All Duplicates In An Array Java
- python--leetcode442. Find All Duplicates in an Array
- 25.leetCode442:Find All Duplicates in an Array
- LeetCode442. Find All Duplicates in an Array解题
- 虚拟继承
- android自定义表盘
- Bangu详解(一)----驱动LCD1602液晶显示屏
- ubuntu05.04 linux2.6.10 内核安装
- ios 校验
- leetcode442
- Linux作业-day04
- __define_initcall
- c++多态性和抽象类综合
- mui
- css中定义font-face的使用方法
- 微信小程序实例源码大全下载
- Swift 中?和!
- 微软 Power BI