@@ -0,0 +1,1032 @@
+import java.util.HashMap;%0A%0A/**%0A * Problem: #136 Single Number%0A *%0A * Idea:%0A *%0A * Solutions:%0A *  singleNumberHash: using a hash map to store unique characters found.%0A *  singleNumber:%0A */%0Apublic class SingleNumber %7B%0A    public int singleNumberHash(int%5B%5D nums) %7B%0A        HashMap%3CInteger, Integer%3E map = new HashMap%3C%3E();%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A            if (map.containsKey(nums%5Bi%5D)) %7B%0A                map.remove(nums%5Bi%5D);%0A            %7D else %7B%0A                map.put(nums%5Bi%5D, i);%0A            %7D%0A        %7D%0A        return (Integer) map.keySet().toArray()%5B0%5D;%0A    %7D%0A%0A    /**%0A     * Need to sort the array first.%0A     */%0A    public int singleNumber(int%5B%5D nums) %7B%0A        if (nums.length == 1) %7B%0A            return nums%5B0%5D;%0A        %7D%0A%0A        //Net%0A        for (int i = 0; i %3C nums.length - 1; i++) %7B%0A            if (nums%5Bi%5D == nums%5Bi+1%5D) %7B%0A                i ++;%0A            %7D else %7B%0A                return nums%5Bi%5D;%0A            %7D%0A        %7D%0A        throw new IllegalArgumentException(%22No solution found.%22);%0A    %7D%0A%7D%0A

Add new solution