C++算法题_第一周
来源:互联网 发布:2016淘宝客刷销量 编辑:程序博客网 时间:2024/05/28 23:23
题目来源 点击打开链接
题目详情
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) { int leng = nums.size(); map<int, bool> twice; vector<int> ret; for(int i = 0; i < leng; i++){ map<int, bool>::iterator it; it = twice.find(nums[i]); if(it != twice.end()) twice[nums[i]] = 1; else{ twice[nums[i]] = 0;}}map<int, bool>::iterator itr;itr = twice.begin();for(; itr!=twice.end(); itr++){if((*itr).second) ret.push_back((*itr).first);}return ret; }};
0 0
- C++算法题_第一周
- 第一周编程题_分数
- 第一周LeetCode算法题之一
- 第一周LeetCode算法题之二
- 第一周:算法概论
- 算法第一周作业
- 算法第一周作业
- Coursera算法第一周
- 算法课第一周
- 算法分析第一周
- 算法第一周
- Fireworks焦祺_第一周
- 程序设计与算法(一)C语言程序设计CAP 第一周
- MOOC C语言程序设计 第一周编程题
- 第一周作业-算法概论
- 《算法概论》第一周作业
- 算法 第一周课外作业
- 第一周算法概论作业
- cocos creator触摸事件 cc.node.EventType
- CTF常见php猥琐小段代码审计
- PAT A1099. Build A Binary Search Tree (30)
- http请求获取json字符串的方法
- 爬取抗压吧的《猪狗恩仇录》
- C++算法题_第一周
- Dubbo|Dubbox 源码解读略析
- java安全架构____java HMAC加密
- 50个很棒的python模块
- Android Studio如何导入第三方主题
- 在android 下支持ntfs-3g
- 1004. 成绩排名 (20)
- (Java学习笔记5.1)简单排序
- 尚硅谷java学习笔记——13.java反射机制