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

[树/链表/图] 大家有没有什么好的写binary tree的心得啊?

🔗
WarriorZ 2019-8-9 13:48:57 | 只看该作者
全局:
crazycodyman 发表于 2019-8-9 11:54
怎么说呢,preorder/inorder/postorder我会用迭代来写一遍,其他统统递归,面试要求我用迭代的话就当没缘 ...

I just read an interesting interview question. Give you the root of a binary tree. find the largest absolute difference from the ancestor and its children. For example
                  5
               /     \
             7        9
                    /     \
                   1      10
in this case, 9 - 1 = 8 is the result. Can you solve it in 20 mintues? Top-down is trivial, can you implement bottom-up? also, can you implement an iterative solution? It is only a medium tag question but I think not everyone could solve it.

评分

参与人数 1大米 +1 收起 理由
咸鱼也有春天 + 1 给你点个赞!

查看全部评分

回复

使用道具 举报

🔗
WarriorZ 2019-8-9 13:52:38 | 只看该作者
全局:
WarriorZ 发表于 2019-8-9 13:48
I just read an interesting interview question. Give you the root of a binary tree. find the larges ...

The child not only including left and right child, but also the children of the left or right child.
回复

使用道具 举报

🔗
qhdxw1996 2019-8-9 13:58:01 | 只看该作者
全局:
哈哈哈大家都刷这么多遍吗一遍不够两遍应该能背下来了吧
回复

使用道具 举报

🔗
kigh103 2019-8-9 14:01:49 | 只看该作者
全局:
关键的地方就是, 什么时候走右枝,什么时候走左枝,什么时候停,如何完成剩余的单边树,你需要根据你自己的习惯总结一个模版,这样有助于记忆和提高准确度。

评分

参与人数 1大米 +1 收起 理由
咸鱼也有春天 + 1 给你点个赞!

查看全部评分

回复

使用道具 举报

🔗
337845818 2019-8-9 21:38:26 | 只看该作者
全局:
可以一对一交流一下哈哈
回复

使用道具 举报

🔗
oceannight 2019-8-9 22:24:01 | 只看该作者
全局:
刷了第三遍还是没太搞明白的飘过。。。。。。
我已经放弃了, 我想说我先背答案吧。。。。
回复

使用道具 举报

🔗
 楼主| 咸鱼也有春天 2019-8-10 00:27:36 | 只看该作者
全局:
WarriorZ 发表于 2019-8-9 13:52
The child not only including left and right child, but also the children of the left or right chil ...

bottom up 一脸懵比。。
回复

使用道具 举报

🔗
yanjinbin 2019-8-11 16:18:59 | 只看该作者
全局:
我觉得遍历的几种方式要熟记于心
回复

使用道具 举报

🔗
littlechen32 2019-8-11 16:30:56 | 只看该作者
全局:
iterative 有一种线索化神级遍历方法。。但是一般也不考,主要就那三种顺序遍历来回玩(dfs),最多一个bfs。一般我都从宏观开始看,第一搞清楚函数定义是什么,要做什么。然后你就看,是先处理当前的节点,还是当前节点的处理需要child的结果,然后你就可以写出递归骨架,最后加上base case,也就是递归函数stack最深那层。也就行了。
回复

使用道具 举报

🔗
littlechen32 2019-8-11 16:31:38 | 只看该作者
全局:
337845818 发表于 2019-8-9 21:38
可以一对一交流一下哈哈

头像很强。。。
回复

使用道具 举报

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

本版积分规则

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