public static int[] singleNumber(int[] array) { int ret = 0; for (int n : array) { ret ^= n; } int div = 1; while ((div & ret) == 0) { div <<= 1; } int a = 0, b = 0; for (int n : array) { if ((div & n) != 0) { a ^= n; } else { b ^= n; } } if (a>b) { return new int[]{b, a}; }else { return new int[]{a, b}; } }