由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Given an array of N integers from range [0, N] and one is missing. Find the missing number.
相关主题
Amazon 2nd Phone Interview问一个面试题
Google电话面试题目这些找missing number的题是不是都不能用求和做?
请教一道题目Given an int array and an int value. Find all pairs in arr
问一道老题这个怎么弄?
问一道面试题目请教一个题目
请教一个面试题请教一道L的题
probably XOR problem求问一个题
请教一个数论的问题彭博 面试题
相关话题的讨论汇总
话题: missing话题: find话题: given话题: array话题: number
进入JobHunting版参与讨论
1 (共1页)
Y******l
发帖数: 19
1
Given an array of N integers from range [0, N] and one is missing. Find the
missing number.
1) how to find the missing number if the element of array is integer value
2) if the element of the array is a bit vector, presenting the integer
number. for example, 000 --> 0, 010 --> 2.
p*****2
发帖数: 21240
2

the
第一问求和吧。第二问亦或吧。

【在 Y******l 的大作中提到】
: Given an array of N integers from range [0, N] and one is missing. Find the
: missing number.
: 1) how to find the missing number if the element of array is integer value
: 2) if the element of the array is a bit vector, presenting the integer
: number. for example, 000 --> 0, 010 --> 2.

b******g
发帖数: 1721
3
for the second, transform the presentation from a bit vector to an integer, and then run the first algorithm.
For the xor operation, does that require the N should be equal to 2^m or just any integer number?
Y******l
发帖数: 19
4

, and then run the first algorithm.
just any integer number?
是啊,我也有同样的疑问,如果N不是2^m.. 有什么快速的方法吗?

【在 b******g 的大作中提到】
: for the second, transform the presentation from a bit vector to an integer, and then run the first algorithm.
: For the xor operation, does that require the N should be equal to 2^m or just any integer number?

k***t
发帖数: 276
5
第一个异或。第二个或(初值零)或者与(初值为up to N bit 全一,与每个element的反)。

, and then run the first algorithm.
just any integer number?

【在 b******g 的大作中提到】
: for the second, transform the presentation from a bit vector to an integer, and then run the first algorithm.
: For the xor operation, does that require the N should be equal to 2^m or just any integer number?

p*****2
发帖数: 21240
6

a^b^c
a^b
a^b^c^a^b=c^0=c

【在 Y******l 的大作中提到】
:
: , and then run the first algorithm.
: just any integer number?
: 是啊,我也有同样的疑问,如果N不是2^m.. 有什么快速的方法吗?

b******g
发帖数: 1721
7
nice, so N does not need to be 2^m.
http://www.geeksforgeeks.org/archives/580
has a more detailed example. Hope this helped other guys.

【在 p*****2 的大作中提到】
:
: a^b^c
: a^b
: a^b^c^a^b=c^0=c

b******g
发帖数: 1721
8
can you explain the second solution a little bit more?

element的反)。

【在 k***t 的大作中提到】
: 第一个异或。第二个或(初值零)或者与(初值为up to N bit 全一,与每个element的反)。
:
: , and then run the first algorithm.
: just any integer number?

t****y
发帖数: 27
9
For the second question, do XOR with 1..N bit by bit should be fine

the

【在 Y******l 的大作中提到】
: Given an array of N integers from range [0, N] and one is missing. Find the
: missing number.
: 1) how to find the missing number if the element of array is integer value
: 2) if the element of the array is a bit vector, presenting the integer
: number. for example, 000 --> 0, 010 --> 2.

1 (共1页)
进入JobHunting版参与讨论
相关主题
彭博 面试题问一道面试题目
问一道CareerCup里的题目请教一个面试题
一道面试题probably XOR problem
一个小公司面经请教一个数论的问题
Amazon 2nd Phone Interview问一个面试题
Google电话面试题目这些找missing number的题是不是都不能用求和做?
请教一道题目Given an int array and an int value. Find all pairs in arr
问一道老题这个怎么弄?
相关话题的讨论汇总
话题: missing话题: find话题: given话题: array话题: number