标签:
先找到两个cand在某一位不相同, 在分别异或
public class Solution { public int[] singleNumber(int[] nums) { int tmp = nums[0]; for (int i = 1; i < nums.length; i++) { tmp ^= nums[i]; } int i = 0; for (; i < 32; i++) { if (((1 << i) & tmp) != 0) { break; } } int can1 = 0; int can2 = 0; for (int num : nums) { if (((1 << i) & num) == 0) { can1 ^= num; } else { can2 ^= num; } } return new int[]{can1, can2}; } }
标签:
原文地址:http://www.cnblogs.com/vision-love-programming/p/5002784.html