SingleNumberSolution { static int singleNumber(int[] nums) { if (nums == null) return -1; if (nums.length == 1) return nums[0]; int result = 0; for (int num : nums) { result ^= num; } return result; }    }
@Test public void singleNumber() { assertEquals(-1, SingleNumberSolution.singleNumber(null)); assertEquals(0, SingleNumberSolution.singleNumber(new int[]{})); assertEquals(1, SingleNumberSolution.singleNumber(new int[]{1})); assertEquals(2, SingleNumberSolution.singleNumber(new int[]{1, 1, 2, 3, 5, 4, 4, 3, 5})); }