求数组中不重复的两个数

import java.util.Arrays;

public class Solution {
    public int[] singleNumber(int[] nums) {
        int[] result = new int[2];
        int res = 0;
        for(int d : nums){
            res ^= d;
        }

        int temp = res;
        int bitOp = res;
        int count = 0;
        while (bitOp != 0 && (bitOp&1) != 1){
            bitOp >>= 1;
            count++;
        }

        for(int d : nums){
            if(((d>>count)&1) == 1){
                temp ^= d;
            }
        }

        result[0] = temp;
        result[1] = temp ^ res;
        return result;
    }
    public static void main(String[] args){
        System.out.println(Arrays.toString(new Solution().singleNumber(new int[]{43772400,1674008457,1779561093,744132272,1674008457,448610617,1779561093,124075538,-1034600064,49040018,612881857,390719949,-359290212,-812493625,124732,-1361696369,49040018,-145417756,-812493625,2078552599,1568689850,865876872,865876872,-1471385435,1816352571,1793963758,2078552599,-1034600064,1475115274,-119634980,124732,661111294,-1813882010,1568689850,448610617,1347212898,-1293494866,612881857,661111294,-1361696369,1816352571,-1813882010,-359290212,1475115274,1793963758,1347212898,43772400,-1471385435,124075538,-1293494866,-119634980,390719949})));
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值