孩子面试时,被测的 两道小题

来源: 兄贵 2023-04-02 08:04:23 [] [博客] [旧帖] [给我悄悄话] 本文已被阅读: 次 (4597 bytes)
本文内容已被 [ 兄贵 ] 在 2023-04-02 09:45:34 编辑过。如有问题,请报告版主或论坛管理删除.

1)一百个从1到100的数组中,混进了一个数(也是从1到100),求算法找出 重复的数,并给出最有效的O() complexity,  both time complexity and space complexity。

test case:

input (101个数字): 

1 2 3 4 5 6 7 8 9 10 11 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
 
output:11
 
2) 判断一个数字是不是 2的指数次方
 
test case 1:
input: 64
out put: True
 
test case 2:
input: 48
out put: False

所有跟帖: 

兄贵,这次有失水准啊。先赞美了 -avw- 给 avw 发送悄悄话 (0 bytes) () 04/02/2023 postreply 08:22:33

为什么? 挺难又很好的题 -兄贵- 给 兄贵 发送悄悄话 兄贵 的博客首页 (0 bytes) () 04/02/2023 postreply 09:46:58

简单搜索的东西 -tibuko- 给 tibuko 发送悄悄话 tibuko 的博客首页 (0 bytes) () 04/02/2023 postreply 08:26:32

谢谢尝试,但是面试失败 -兄贵- 给 兄贵 发送悄悄话 兄贵 的博客首页 (0 bytes) () 04/02/2023 postreply 09:48:14

第一题,你题目中没说是排好的,test的数字已经排好了,这到底咋回事? -avw- 给 avw 发送悄悄话 (0 bytes) () 04/02/2023 postreply 08:38:31

谢谢,不必排好,我偷懒举了排好的例子 -兄贵- 给 兄贵 发送悄悄话 兄贵 的博客首页 (0 bytes) () 04/02/2023 postreply 09:44:17

答案呢? -zhucekunnan- 给 zhucekunnan 发送悄悄话 (0 bytes) () 04/02/2023 postreply 10:41:51

请您先登陆,再发跟帖!

发现Adblock插件

如要继续浏览
请支持本站 请务必在本站关闭/移除任何Adblock

关闭Adblock后 请点击

请参考如何关闭Adblock/Adblock plus

安装Adblock plus用户请点击浏览器图标
选择“Disable on www.wenxuecity.com”

安装Adblock用户请点击图标
选择“don't run on pages on this domain”