Then the bitvector method cannot work. You should keep the order of element in the original array. For example, 4 3 3 6 6 2 7 7 1 You need to get 4 3 6 2 7 1 Using bitvector, you only get 1 2 3 4 6 7
【在 d**e 的大作中提到】 : 返回新数组,重复元素取第一个
a*y
18 楼
hehe ,type, 1G
d*e
19 楼
don't scan the bitvector, you can do this: for e in input_array if bitvector(e) is 1 then append e to result set bitvector(e) to 0 end if end for
【在 h****n 的大作中提到】 : Then the bitvector method cannot work. : You should keep the order of element in the original array. : For example, : 4 3 3 6 6 2 7 7 1 : You need to get 4 3 6 2 7 1 : Using bitvector, you only get 1 2 3 4 6 7
【在 h****n 的大作中提到】 : Then the bitvector method cannot work. : You should keep the order of element in the original array. : For example, : 4 3 3 6 6 2 7 7 1 : You need to get 4 3 6 2 7 1 : Using bitvector, you only get 1 2 3 4 6 7
g*e
21 楼
我最近面试老问排序in place去重 以后也可以问问你这题
【在 d**e 的大作中提到】 : don't scan the bitvector, you can do this: : for e in input_array : if bitvector(e) is 1 then : append e to result : set bitvector(e) to 0 : end if : end for
h*n
22 楼
Well, I see. But this method seems to be just a simplified version of HashSet, doesn't it?
【在 d**e 的大作中提到】 : don't scan the bitvector, you can do this: : for e in input_array : if bitvector(e) is 1 then : append e to result : set bitvector(e) to 0 : end if : end for
d*e
23 楼
yes... the idea is the same... i thought what he wanted to know was 1) if i can code 2) if i know HashSet 3) if i know bitvector
it?
【在 h****n 的大作中提到】 : Well, I see. : But this method seems to be just a simplified version of HashSet, doesn't it?
j*2
24 楼
所以还是要扫三遍是不
【在 d**e 的大作中提到】 : don't scan the bitvector, you can do this: : for e in input_array : if bitvector(e) is 1 then : append e to result : set bitvector(e) to 0 : end if : end for
l*c
25 楼
谁能回答我一个弱问啊? 在C++里面,用unordered_map做这道题的时候,应该用related int AS the key吧?那 在hashtable里面存的什么呢?unordered_map不是两个elements吗?一个key,另一个 是啥呢?谢谢。
g*y
26 楼
用set 就好了吧,不用map
【在 l****c 的大作中提到】 : 谁能回答我一个弱问啊? : 在C++里面,用unordered_map做这道题的时候,应该用related int AS the key吧?那 : 在hashtable里面存的什么呢?unordered_map不是两个elements吗?一个key,另一个 : 是啥呢?谢谢。
l*c
27 楼
谢谢,但是还是O(1)的吗?
【在 g****y 的大作中提到】 : 用set 就好了吧,不用map
a*y
28 楼
No, set is a binary tree which is O(logn),就用unordered——map好了
【在 l****c 的大作中提到】 : 谢谢,但是还是O(1)的吗?
l*c
29 楼
我在想可不可以用unordered_set
【在 a*******y 的大作中提到】 : No, set is a binary tree which is O(logn),就用unordered——map好了