260. Single Number III
来源:互联网 发布:visio2007软件下载 编辑:程序博客网 时间:2024/04/27 11:10
Given an array of numbers nums
, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.
For example:
Given nums = [1, 2, 1, 3, 2, 5]
, return [3, 5]
.
Note:
- The order of the result is not important. So in the above example,
[5, 3]
is also correct.
- Your algorithm should run in linear runtime complexity. Could you implement it using only constant space complexity
solution:
class Solution {public: vector<int> singleNumber(vector<int>& nums) { vector<int> res; map<int,int> m; for(int i=0; i<nums.size(); i++){ auto ret = m.insert(make_pair(nums[i],1)); if(!ret.second) m[nums[i]] = 2; } for(auto it=m.begin(); it!=m.end(); it++){ if((*it).second==1) res.push_back((*it).first); } return res; }};
运行速度:慢
0 0
- 260.Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 安卓Xutils3网络工具,注解工具,图片工具和日志工具的使用,以及对网络工具的封装
- bzoj 1066: [SCOI2007]蜥蜴
- 代码规范和Android项目中的一些可用工具
- Unity教程之-制作闪亮的星星Star(四):Unity Editor编辑器实现Undo
- 使用RNN解决NLP中序列标注问题的通用优化思路
- 260. Single Number III
- eclipse中删除Android Private libraries后没有自动生成
- Java 递归形式深度优先遍历二叉树
- Base64 —— 编码/解码
- 【Tomcat】配置+部署
- Java 非递归方式深度优先遍历二叉树
- 管教管教那些不听话的view
- Xcode工具的使用---设置代码折叠
- 《笨办法学Python》 第43课手记