LeetCode 260
2016-04-24 23:15
148 查看
Single Number III
Given an array of numbers
For example:
Given
Note:
The order of the result is not important. So in the above example,
Your algorithm should run in linear runtime complexity. Could you implement it using only constant space complexity?
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?
public class Solution { public int[] singleNumber(int[] nums) { Set<Integer> set = new HashSet<Integer>(); for(int i:nums){ if(set.add(i) == false){ set.remove(i); } } int a[] = new int [set.size()]; int b = 0; for(int c:set){ a[b] = c; b++; } return a; } }
相关文章推荐
- Git与eclipse--(一)
- Android studio中提示 Error inflating class fragment错误
- 20145219 《Java程序设计》实验三 敏捷开发与XP实践
- 快速反射DataTable
- javascript中try catch finally 的使用
- 百度地图宣布国际化战略
- 百度地图宣布国际化战略
- LeetCode 258
- 说说中断上下文的切换
- CompileSdkVersion和buildeToolVersion版本号关系
- ios开发总结之控制器的生命周期
- 20144303 第三次实验
- 监控页面所有 ajax请求
- js中如何获取该浏览器的类型
- MySQL单表多关键字模糊查询的实现
- LeetCode 237
- CreateProcessW的参数陷阱
- PHP 实现木桶算法
- 20145238-荆玉茗 《Java程序设计》实验三
- 每周收获(8-10)