查看: 1282| 回复: 4
跳转到指定楼层
上一主题 下一主题
收起左侧

[CareerCup] [第二轮] 3/18-3/24 CareerCup 4.9

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
You are given a binary tree in which each node contains a value. Design an algorithm to print all paths which sum to a given value. Note that a path can start or end anywhere in the tree.

发帖规范:
http://www.1point3acres.com/bbs/thread-48094-1-1.html
http://www.1point3acres.com/bbs/thread-32423-1-1.html

上一篇:[第二轮] 3/18-3/24 CareerCup 4.8
下一篇:[第二轮] 3/18-3/24 CareerCup 5.1
🔗
EchoMemory 2013-3-19 17:27:10 | 只看该作者
全局:
I suppose dfs could solve that. no good idea...
回复

使用道具 举报

🔗
moophis 2013-3-20 20:49:42 | 只看该作者
全局:
Using DFS and dynamic programming may solve the problem if I'm allowed to add an extra integer as index to each node.
https://github.com/moophis/careercup/blob/master/4.9.cpp
回复

使用道具 举报

🔗
ThunderXu 2013-3-23 20:27:36 | 只看该作者
全局:
https://gist.github.com/ThunderXu/5227537
use recursion, find paths start from the current node for every node
回复

使用道具 举报

全局:
https://github.com/1094401996/Ca ... t9/FindSumPath.java
* 此题很好,综合使用了递归和一些编程的小技巧, 我这个智商果断没自己想出来。。。。答案是如此的优雅。。。。
* 第一步:树的高度为N, 建立一个path数组,长度为N + 1
* 第二步:递归遍历每个节点, 对每个节点都findsum函数, on every node, we look "up " to see if
* we have found the sum, that is rather than asking" does this node start a path
* with the sum " , we ask, "does this node complete the path with the sum.This description
* cited from solution is terrific. I must maintain the thinking pattern
回复

使用道具 举报

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

本版积分规则

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