楼主: magict42
跳转到指定楼层
上一主题 下一主题
收起左侧

[CareerCup] [第二轮] 3/11-3/17 CareerCup 4.1

全局:
*  method1: calculate the height of every node....
*  method2: we don't need to calculate the height of every node....
the default leaf height  is zero......
https://github.com/1094401996/Ca ... ot1/IsBalanced.java
回复

使用道具 举报

🔗
ThunderXu 2013-3-16 11:17:29 | 只看该作者
全局:
https://gist.github.com/ThunderXu/5174776
use recursion to calculate depth of leftchild and rightchild for every node
回复

使用道具 举报

🔗
weep_willow 2013-3-17 12:19:35 | 只看该作者
全局:
recursively find the maxDepth and minDepth, evaluate whether its balanced or not by the different of the minDepth and maxDepth

C++ implementation

https://github.com/StanleyLee/CareerCup/blob/master/4_1.cpp
回复

使用道具 举报

🔗
weep_willow 2013-3-17 12:19:48 | 只看该作者
全局:
recursively find the maxDepth and minDepth, evaluate whether its balanced or not by the different of the minDepth and maxDepth

C++ implementation

https://github.com/StanleyLee/CareerCup/blob/master/4_1.cpp
回复

使用道具 举报

🔗
sing1ee 2013-3-17 23:11:21 | 只看该作者
全局:
weep_willow 发表于 2013-3-17 12:19
recursively find the maxDepth and minDepth, evaluate whether its balanced or not by the different of ...

平衡,仅仅考察根节点是不够的,需要每个节点都要考察。如下case
------------------a
--------------b------c
--------d---------------e
----f
只有根节点满足最大最小深度相差不超过1.
回复

使用道具 举报

🔗
weep_willow 2013-3-18 23:09:24 | 只看该作者
全局:
sing1ee 发表于 2013-3-17 23:11
平衡,仅仅考察根节点是不够的,需要每个节点都要考察。如下case
------------------a
--------------b ...

谢谢你的回复,我觉得你给的这种情况可以判断是不平衡啊
我手动递归的推了一下 maxDepth=4, minDepth=2, 4-2>1, 所以程序返回应该为不平衡, 我觉得没有问题啊
回复

使用道具 举报

🔗
sing1ee 2013-3-19 09:59:01 | 只看该作者
全局:
本帖最后由 sing1ee 于 2013-3-19 10:03 编辑
weep_willow 发表于 2013-3-18 23:09
谢谢你的回复,我觉得你给的这种情况可以判断是不平衡啊
我手动递归的推了一下 maxDepth=4, minDepth=2, ...

我的例子举得不对=.=


看看百科这个例子。按照你的思路,是不是maxDepth=5, minDepth=3?
回复

使用道具 举报

🔗
weep_willow 2013-3-19 12:13:54 | 只看该作者
全局:
sing1ee 发表于 2013-3-19 09:59
我的例子举得不对=.=

我觉得是啊 所以不是balanced啊
回复

使用道具 举报

🔗
天道酬勤 2013-3-30 01:13:18 | 只看该作者
全局:
回复

使用道具 举报

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

本版积分规则

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