Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 给定一个整数数组,其中除一个数出现两次外,每个数都出现三次,找到出现两次的数?_Arrays_Duplicates_Operators_Bitwise Operators_Xor - Fatal编程技术网

Arrays 给定一个整数数组,其中除一个数出现两次外,每个数都出现三次,找到出现两次的数?

Arrays 给定一个整数数组,其中除一个数出现两次外,每个数都出现三次,找到出现两次的数?,arrays,duplicates,operators,bitwise-operators,xor,Arrays,Duplicates,Operators,Bitwise Operators,Xor,这是一个来自“节目采访要素”的问题。我看到这个问题贴了出来,但接受的答案(或其他答案)并不完整 使用在base 3系统上工作的类似XOR的操作(在文章中称为xor3),您将得到xor3 x。但是,问题是要获得xxor3定义为模3的加法(其中数字以基数3表示) 如何从xor3 x中提取x部分?如果您再次检查数字数组,会怎么样?假设第一次迭代后的值是a=x xor3 x 遍历数组中的所有条目,并使用a遍历每个值 for y in arr: if y xor3 a == 0:

这是一个来自“节目采访要素”的问题。我看到这个问题贴了出来,但接受的答案(或其他答案)并不完整

使用在base 3系统上工作的类似XOR的操作(在文章中称为
xor3
),您将得到
xor3 x
。但是,问题是要获得
x
xor3
定义为模3的加法(其中数字以基数3表示)


如何从
xor3 x
中提取
x
部分?

如果您再次检查数字数组,会怎么样?假设第一次迭代后的值是
a=x xor3 x

遍历数组中的所有条目,并使用
a
遍历每个值

for y in arr:
    if y xor3 a == 0:
        print y
        break
    else
        continue
目前,我认为这是一个幼稚的解决方案。考虑到每个
xor3
都是具有O(1)内存的O(1),这仍然是O(n)