题目
类型:bitManipulation
解题思路


一个数和它本身的负数做按位与的运算后可以得到这个数二进制中最低位的那个1。
比如说6&-6,结果是2,6的二进制位0110,最低位的1就是2。
代码
class Solution {public int[] singleNumber(int[] nums) {int xorsum = 0;for (int num : nums) {xorsum ^= num;}// 防止溢出int lsb = (xorsum == Integer.MIN_VALUE ? xorsum : xorsum & (-xorsum));int type1 = 0, type2 = 0;for (int num : nums) {if ((num & lsb) != 0) {type1 ^= num;} else {type2 ^= num;}}return new int[]{type1, type2};}}



