avatar
Y*l
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.
avatar
p*2
3

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.

avatar
b*g
5
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?
avatar
N*u
6
我家是看图说话,不必拘泥于书上的说明。看动画片只有粑粑麻麻吃饭的时候。
avatar
Y*l
7

, 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?

avatar
r*f
8
什么,你干嘛不给她吃饭....
rocket run

【在 N******u 的大作中提到】
: 我家是看图说话,不必拘泥于书上的说明。看动画片只有粑粑麻麻吃饭的时候。
avatar
k*t
9
第一个异或。第二个或(初值零)或者与(初值为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?

avatar
p*2
10

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.. 有什么快速的方法吗?

avatar
b*g
11
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

avatar
b*g
12
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?

avatar
t*y
13
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.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。