📣 独立日限时特惠: VIP通行证立减$68
12
返回列表 发新帖
楼主: wrj5518
跳转到指定楼层
上一主题 下一主题
收起左侧

[CareerCup] 【第三轮】7.7-7.13 CareerCup 4.3

全局:
圆梦梦剧场 发表于 2014-7-11 23:13
为什么楼上的你们的空间复杂度都是O(n)?不应该是O(log n)么

因为 虽然递归用了logN的空间
但是返回值,也就是建立好的tree占用了O(n)的空间
所以总的空间复杂度应该还是O(n)
回复

使用道具 举报

🔗
林微熙 2014-7-12 03:20:05 | 只看该作者
全局:
【解题思路】bst, 从中间取,左右各为一半,计算
【时间复杂度】o(n)
【空间复杂度】O(n)
【gist link】https://gist.github.com/hilda8519/60367ae3e1a6b4dc0c49
回复

使用道具 举报

🔗
ivycheung1208 2014-7-13 03:44:07 | 只看该作者
全局:
【解题思路】
recursively create sub-trees, return pointer to the root. return null pointer when start and end pointer overlaps.
【时间复杂度】
O(N)
【空间复杂度】
O(N)
【gist link】
https://gist.github.com/befe79a84c97f985489f
回复

使用道具 举报

🔗
兰橘清檬 2014-7-13 08:53:36 | 只看该作者
全局:
【解题思路】
recursively create sub-trees, return pointer to the root.
return null pointer when start and end pointer overlaps.
【时间复杂度】
O(N)
【空间复杂度】
O(N)
【gist link】
https://gist.github.com/JoyceeLee/627488dd7113966bfd92
回复

使用道具 举报

🔗
wilbert 2014-7-14 05:45:05 | 只看该作者
全局:
【解题思路】
since we are creating BST from sorted array, the middle element of the array is the root of the BST. using divide and conquer to build the left and right subtree from left and right subarray.
【时间复杂度】
O(N)
【空间复杂度】
O(N)
【gist link】
https://gist.github.com/iwilbert/3b0c485726cd15632bef
回复

使用道具 举报

🔗
jyh橘子 2014-7-15 15:46:33 | 只看该作者
全局:
【解题思路】recursive solution. The middle element should be the root of the tree, the left half be the left subtree and the right half become to the right subtree
【时间复杂度】O(N)
【空间复杂度】O(N)
【gist】https://gist.github.com/jyhjuzi/8af477cdc9f92a57d842
回复

使用道具 举报

🔗
renli3000 2014-7-18 04:37:37 | 只看该作者
全局:
【解题思路】 recursion: add the middle number first, then access left haft and right half.
值得注意的是最后一个元素会被漏掉,在第归出口判断一下就行了
懒得建树了,最后只把建树的顺序存在了一个queue里

【时间复杂度】O(N)
【空间复杂度】O(N)
【gist】https://gist.github.com/Noahsark/067a9ff44fe49274788d

回复

使用道具 举报

🔗
tonygxxx1212 2014-7-19 22:20:03 | 只看该作者
全局:

【解题思路】recursive solution. The middle element should be the root of the tree, the left half be the left subtree and the right half become to the right subtree
【时间复杂度】O(N)
【空间复杂度】O(N)
【gist】 https://gist.github.com/xun-gong/bcc74b741c02535a5d1e
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表