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

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

全局:

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

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

x
Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree. Avoid storing additional nodes in a data structure. NOTE: This is not necessarily a binary search tree.

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

上一篇:beautiful method for an interview question
下一篇:[第二轮] 3/18-3/24 CareerCup 4.8
🔗
ThunderXu 2013-3-18 21:29:06 | 只看该作者
全局:
https://gist.github.com/ThunderXu/5187118
if a node has node1 in its left sub-tree and node2 in its right sub-tree, then it is the first common ancestor of node1 and node2
回复

使用道具 举报

全局:
https://github.com/1094401996/Ca ... CommonAncestor.java

对自己的智力彻底丧失信心了。。。难道自己不是码农的材料
回复

使用道具 举报

🔗
EchoMemory 2013-3-19 17:06:51 | 只看该作者
全局:
Because of avoid storing additional nodes, so just DFS。。。?Otherwise, online or offline algorithm could be used...
回复

使用道具 举报

🔗
EchoMemory 2013-3-19 17:07:55 | 只看该作者
全局:
规格严格理性帝 发表于 2013-3-19 01:17
https://github.com/1094401996/CareerCup/blob/master/Chapter4/src/fourdot7/CommonAncestor.java

对自 ...

原来Java这么简单。。。
回复

使用道具 举报

全局:
EchoMemory 发表于 2013-3-19 02:07
原来Java这么简单。。。

求别黑了。。。
回复

使用道具 举报

🔗
EchoMemory 2013-3-19 23:29:30 | 只看该作者
全局:
本帖最后由 EchoMemory 于 2013-3-19 23:38 编辑
规格严格理性帝 发表于 2013-3-19 21:08
求别黑了。。。

这哪是黑。。。模板写的很赞,学习了~
回复

使用道具 举报

全局:
EchoMemory 发表于 2013-3-19 08:29
这哪是黑。。。模板写的很赞,学习了~

要是我自己写出来的就好了。。。。。。。书上的思路。。。。
回复

使用道具 举报

🔗
grassgigi 2013-3-20 11:43:55 | 只看该作者
全局:
first recursively find path from root to two nodes..用string表示path,往左为0,往右为1,Find the longest common sequence of two path strings
https://gist.github.com/chrislukkk/5202125
BST的话会方便很多..preorder traverse and found the first node that has value between that of two nodes(assume nodes exists in tree).
回复

使用道具 举报

🔗
宋小宝Dani 2013-3-27 16:29:05 | 只看该作者
全局:
https://gist.github.com/5252636.git
recursively find the two nodes from the root's left and right
回复

使用道具 举报

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

本版积分规则

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