260. Single Number III
来源:互联网 发布:手机可以plc编程软件吗 编辑:程序博客网 时间:2024/04/25 17:25
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?
class Solution {public: vector<int> singleNumber(vector<int>& nums) { vector<int> result; map<int, int>m; for(int i = 0; i < nums.size(); i++){ if(m.find(nums[i])==m.end()) m[nums[i]] = 1; else m[nums[i]]++; } for(int j = 0; j < nums.size(); j++){ if(m[nums[j]]<2) result.push_back(nums[j]); } return result; }};
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
- socket长连接和socket短连接
- php精度计算
- ZOJ 3872 Beauty of Array【dp】
- Android 学习记录-Activity生命周期
- ICMP扫描
- 260. Single Number III
- 5.中断
- 找不到或无法加载主类
- HDOJ 1907 John && NOJ 1927 谁才是最强战舰!
- 如何在CentOS6.5系统上安装Oracle11gR2数据库
- Java8クラス
- 康托展开
- 关于getting 'android:label' attribute: attribute is not a string value 错误的解决方法
- 搜索—Problem_1019-N皇后问题