12
返回列表 发新帖
楼主: wrj5518
跳转到指定楼层
上一主题 下一主题
收起左侧

[CareerCup] 【第三轮】7.14-7.20 CareerCup 4.9

🔗
bitcpf 2014-7-22 01:18:59 | 只看该作者
全局:
【解题思路】recursion, if current node key equals to the remaining sum value, return, else check the left and right subtree
second recursion to check each node as root

【时间复杂度】
O(N^2)
【空间复杂度】
O(lgN) for node list to represent the path

【gist link】
https://gist.github.com/bitcpf/8beb7c1e035c08461596
回复

使用道具 举报

🔗
wilbert 2014-7-23 09:09:29 | 只看该作者
全局:
【解题思路】
recursively tree traversal, and save the path in the array, calculate the sum from that node, and print the path if equals to target.
【时间复杂度】
O(N*h) h is the height of the tree
【空间复杂度】
O(h)
【gist link】
https://gist.github.com/iwilbert/b42b689943beb2a1d3df
回复

使用道具 举报

🔗
兰橘清檬 2014-8-14 04:26:55 | 只看该作者
全局:
【解题思路】
DFS recursion, check if the current node is the end of the valid path
【时间复杂度】
   O(nlog(n))
   if balanced tree; or O(n*h)
【空间复杂度】
  O(h)
【gist link】
  https://gist.github.com/JoyceeLee/7a52bbc5937fc1d400c1
回复

使用道具 举报

🔗
yyz20002008 2014-12-16 07:00:31 | 只看该作者
全局:
请问这道题要不要考虑root作为中间节点的的情况 比如 求sum=21,root=7,root.left=10,root.right=4,返回10,7,4 or 7 10 4作为一个结果。书上只考虑了root左边或右边的从上到下任意点开始,但start anywhere理论上不得包含从左节点到右节点的情况吗?
多谢指教了
回复

使用道具 举报

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

本版积分规则

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