查找数组中只出现一次的数(一)——Leetcode系列(十四)
2014-06-30 20:18
232 查看
Single Number
Given an array of integers, every element appears twice except for one.
Find that single one.
Note:
Your algorithm should have a linear runtime complexity.
Could you implement it without using extra memory?
My Answer:
public class Solution { public int singleNumber(int[] A) { Set<Integer> set = new HashSet<Integer>(); int length = A.length; for(int i = 0; i < length; i++){ if(set.contains(A[i])){ set.remove(new Integer(A[i])); }else{ set.add(A[i]); } } Iterator<Integer> ite = set.iterator(); return ite.next(); } }
题目来源:https://oj.leetcode.com/problems/single-number/
相关文章推荐
- Leetcode540. 二分查找找出数组中只出现一次的元素
- 【LeetCode】- Single Number(从数组中找出只出现一次的数字)
- 【白话经典算法系列之十七】 数组中只出现一次的数
- LeetCode 260 Single Number III(数组中只出现一次的数字3)
- 查找算法之查找一个数组中只出现过一次的数
- leetcode之位运算取得数组中只出现一次的一个数
- leetcode-singleNum2 找出一个数组中只出现过一次的元素
- 白话经典算法系列之十七 数组中只出现一次的数
- LeetCode 136 Single Number(数组中只出现一次的数字)
- 【白话经典算法系列之十七】 数组中只出现一次的数 其他三次
- leetcode_260. Single Number III 数组中找出两个只出现一次的元素
- 查找数组中三个只出现一次的数字
- LeetCode——Single Number II(找出数组中只出现一次的数2)
- 查找数组中只出现一次的一个数
- 【leetcode】数组中找出只出现一次的数字(Single Number)
- LeetCode——Single Number(找出数组中只出现一次的数)
- 【查找】【位操作】数组中,除某一个数字x之外,其他数字都出现三次,而x出现一次,找出x
- 【白话经典算法系列之十七】 数组中只出现一次的数
- 剑指offer系列-T40找出数组中只出现一次的2个数
- 【剑指offer系列】 数组中只出现一次的数字___40