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

[高频题] 记录贴,互勉

🔗
 楼主| 微信用户_b99d1cc 2023-8-27 06:48:44 | 只看该作者
全局:
669. Trim a Binary Search Tree
Basic idea: if the root < low, all the value of left subtree < low, we want to check the right subtree
if the root > high, all the value of right subtree > high, we need to trim the left subtree

image.png (97.11 KB, 下载次数: 2)

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-8-27 06:55:35 | 只看该作者
全局:
1325. Delete Leaves With a Given Value
We want bottom-top, so we need to put the check condition at the end

image.png (95.02 KB, 下载次数: 2)

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-8-27 07:10:15 | 只看该作者
全局:
112. Path Sum
Every time iterates through a child node, pass the path sum - root.val to the child as targetSum,
the condition is true when the targetSum == child.val

image.png (143.41 KB, 下载次数: 2)

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-8-27 07:42:22 | 只看该作者
全局:
113. Path Sum II
Recursive solution: remove the last element added to the list before returning back.
Problem: when the list is the solution, we need to creat a new ArrayList as ls instead of directly using ls as solution, or it will change the list in our solution list.

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

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-8-28 10:12:06 | 只看该作者
全局:
437. Path Sum III
Use map to map down how many times the pre-sum we have

image.png (31.75 KB, 下载次数: 2)

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-8-29 06:08:56 | 只看该作者
全局:
129. Sum Root to Leaf Numbers
DFS recursive solution

image.png (17.31 KB, 下载次数: 3)

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-8-29 06:17:25 | 只看该作者
全局:
257. Binary Tree Paths
DFS

image.png (24.23 KB, 下载次数: 3)

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-8-29 09:54:20 | 只看该作者
全局:
236. Lowest Common Ancestor of a Binary Tree
Find the common root that left and right are not null.

image.png (29.21 KB, 下载次数: 2)

image.png
回复

使用道具 举报

无效楼层,该帖已经被删除
🔗
sybzd 2023-8-29 16:04:18 | 只看该作者
全局:
lishuzheng1012 发表于 2023-8-15 19:16
中序遍历只写出递归的方法,应该是不会被面试官轻易放过的。很可能让你写迭代的方法,两种都熟练面试官就很 ...

o(N logN) 把,遍历每个结点的时候找下一个都需要遍历left tree。
回复

使用道具 举报

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

本版积分规则

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