算法找到以阵列奇数项(没有对)奇数、阵列、算法

由网友(何必把一切看到那么透°)分享简介:可能重复: 找到一个单一的数字在列表 什么是给定整数数组好的算法,所有,但其中一个出现的偶数次,找到一个整数出现的次数为奇数What to be a good algorithm given an array of integers, all but one of which appears an even nu...

可能重复:   找到一个单一的数字在列表

什么是给定整数数组好的算法,所有,但其中一个出现的偶数次,找到一个整数出现的次数为奇数

What to be a good algorithm given an array of integers, all but one of which appears an even number of times, find the one integer which appears an odd number of times.

也许沿东西折半查找的行?

Perhaps something along the line of binary search ?

总和的N / 2的大小2小数组的所有元素,比较,递归找出?

Sum all elements of 2 small arrays of n/2 size , compare , recursively find out ?

请一些人给的一些想法。

Please some one give some ideas .

我在编辑一个问题:

难道这XOR算法,实际上假定{1,1,4,4,7,7,5,8,8,9,9}?

Is this XOR algorithm actually assuming {1,1,4,4,7,7,5,8,8,9,9} ?

我的输入可以randmon太 - {1,} 4,1,8,9,5,4,5,9,8 - 因此,逻辑的变化?

My input can be randmon too - { 1 ,4,1,8,9,5,4,5,9,8} - So the logic changes ?

推荐答案

异或所有的数组元素。其结果将是,重复的次数奇数元素

XOR all the array elements. The result will be the element that repeats odd number of times.

阅读全文

相关推荐

最新文章