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

[高频题] 记录贴,互勉

🔗
 楼主| 微信用户_b99d1cc 2023-8-30 22:44:03 | 只看该作者
全局:
508. Most Frequent Subtree Sum
map down the most frequency and the sum happended

image.png (30.92 KB, 下载次数: 7)

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-8-30 23:24:19 | 只看该作者
全局:
124. Binary Tree Maximum Path Sum
For the left and right subPath, we need to compare the value with 0, if it less than 0, we don't add it up

image.png (17.91 KB, 下载次数: 8)

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-8-30 23:37:50 | 只看该作者
全局:
543. Diameter of Binary Tree
Diameter means the maximum length of left and right subTree of a root.

image.png (14.59 KB, 下载次数: 8)

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-8-30 23:46:06 | 只看该作者
全局:
687. Longest Univalue Path
We need to pass the root value of the current path to next layer, and check if cur root value equal its parent root value.

image.png (22.23 KB, 下载次数: 6)

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-8-31 00:31:57 | 只看该作者
全局:
968. Binary Tree Cameras
Hard (DFS)
Hint: need to check the root status at the end.
Define the status of each node:
status = 0,1,2 need a camera, don't need, the camera itself

image.png (26.98 KB, 下载次数: 7)

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-8-31 03:53:58 | 只看该作者
全局:
337. House Robber III
Medium
经典题目: take or not take
For the current root node, we can either take or not take, we use a recursive function to calculate the maximum value we can get, we start from the bottom to the top, if we take current node, the child couldn't be take, but the grandchild could be either take or not take.
In this question, we need to use memory to prevent multiple calculations.
As the bottom node already calculated once for its best result, we just need to check whether we take the root value or not take but the maximum value of its left and right child.

image.png (33.63 KB, 下载次数: 307)

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-8-31 05:54:42 | 只看该作者
全局:
979. Distribute Coins in Binary Tree
Medium
For this question, we can think about the question as a root and left right subtree, for each subTree, the coin it need is abs of( sum of add node - number of node (each node need one) ) (Total move needed)  for the root node, the coin we need to give out is, sum of left and right + root.val -1
更多图片 小图 大图
组图打开中,请稍候......
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-8-31 05:55:49 | 只看该作者
全局:
目前为止完成部分Tree相关题目

image.png (37.17 KB, 下载次数: 6)

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-8-31 06:52:40 | 只看该作者
全局:
169. Majority Element
Easy

image.png (6.64 KB, 下载次数: 7)

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-8-31 07:10:35 | 只看该作者
全局:
153. Find Minimum in Rotated Sorted Array Medium
Compare mid and end values in the array return the min value if the array left have only one or two value.

image.png (17.75 KB, 下载次数: 4)

image.png
回复

使用道具 举报

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

本版积分规则

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