package LeetCode.Java;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by tank on 17/3/25.
 */
public class SingleNumber {
    public int singleNumber(int[] nums) {
        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
        for (int i = 0; i < nums.length; i++){
            if (!map.containsKey(nums[i]))
                map.put(nums[i], 1);
            else
                map.replace(nums[i], 2);
        }
        for (Integer key: map.keySet()){
            if (map.get(key) == 1)
                return key;
        }
        return 0;
    }
}


@@ -47,90 +47,380 @@
 ap;%0A
-import java.util.HashSet;%0Aimport java.util.Set;%0A%0A/**%0A * Created by tank on 17/3/25
+%0A/**%0A * Created by tank on 17/3/25.%0A */%0A/**-------------------------Title---------------------------------%0A Given an array of integers, every element appears twice except for one. Find that single one.%0A%0A Note:%0A Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?%0A%0A Subscribe to see which companies asked this question
 .%0A *

136.Single Number