@@ -0,0 +1,1348 @@
+package leetcode251_260;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0A/**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.%0A For example: Given nums = %5B1, 2, 1, 3, 2, 5%5D, return %5B3, 5%5D.%0A Note: The order of the result is not important. So in the above example, %5B5, 3%5D is also correct.%0A Your algorithm should run in linear runtime complexity. Could you implement it using only constant space complexity?%0A * Created by eugene on 16/5/12.%0A */%0Apublic class SingleNumberIII %7B%0A%0A    /**%0A     * http://www.kancloud.cn/kancloud/data-structure-and-algorithm-notes/72983%0A     * %E5%85%88%E5%B0%86%E6%89%80%E6%9C%89%E7%9A%84%E6%95%B0%E5%BC%82%E6%88%96%EF%BC%8C%E5%BE%97%E5%88%B0%E7%9A%84%E5%B0%86%E6%98%AFx%E5%92%8Cy%E4%BB%A5%E5%90%8E%E4%B9%8B%E5%90%8E%E7%9A%84%E5%80%BCxy%E3%80%82%0A     %E6%89%BE%E5%88%B0xy%E4%B8%BA1%E7%9A%84%E6%9F%90%E4%B8%80%E4%BD%8D%EF%BC%88%E4%B8%BA%E4%BA%86%E6%96%B9%E4%BE%BF%E5%B0%B1%E5%8F%96%E6%9C%80%E5%8F%B3%E8%BE%B9%E4%B8%BA1%E7%9A%84%E4%B8%80%E4%BD%8D%EF%BC%8C%E5%8F%96%E6%B3%95%E4%B8%BAxy & ~(xy-1)%EF%BC%8C%0A     %E5%86%8D%E5%B0%86%E8%BF%99%E4%B8%80%E4%BD%8D%E4%B8%BA1%E7%9A%84%E6%89%80%E6%9C%89%E6%95%B0%E5%BC%82%E6%88%96%E5%BE%97%E5%88%B0x%EF%BC%8C%E5%89%A9%E4%B8%8B%E7%9A%84%E6%89%80%E6%9C%89%E6%95%B0%E5%BC%82%E6%88%96%E5%BE%97%E5%88%B0y%E3%80%82%0A     * @param nums%0A     * @return%0A     */%0A    public int%5B%5D singleNumber(int%5B%5D nums) %7B%0A        int%5B%5D result = new int%5B2%5D;%0A        if (nums==null %7C%7C nums.length==0) return result;%0A        int xy = 0;%0A        for (int i: nums)  xy %5E= i;%0A        // get the last 1 bit of xXORy, e.g. 1010 ==%3E 0010%0A        int last1Bit = xy & ~(xy-1);%0A        int x = 0, y = 0;%0A        for (int i: nums) %7B%0A            if ((last1Bit & i) == 0) x %5E= i;%0A            else y %5E= i;%0A        %7D%0A        result%5B0%5D = x;%0A        result%5B1%5D = y;%0A        return result;%0A    %7D%0A%0A%7D%0A

Single Number III