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

[高频题] 记录贴,互勉

无效楼层,该帖已经被删除
🔗
 楼主| 微信用户_b99d1cc 2023-9-8 10:06:20 | 只看该作者
全局:
530. Minimum Absolute Difference in BST
recursive solution( in order )

image.png (19.58 KB, 下载次数: 9)

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-9-8 10:37:07 | 只看该作者
全局:
700. Search in a Binary Search Tree
Hint: BST left < root < right
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-9-8 10:41:50 | 只看该作者
全局:
701. Insert into a Binary Search Tree
Compare left and right node value and decide which brunch need to be insert

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

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-9-8 11:11:58 | 只看该作者
全局:
230. Kth Smallest Element in a BST
In_order

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

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-9-9 08:37:31 | 只看该作者
全局:
99. Recover Binary Search Tree
(Exactly two nodes of the tree were swapped by mistake)
In this case, we use in order traversal to recursively visit the BST.
Case one: 1 4 3 2 5    4 and 2 need to be swap, in this case node1 is pre, node2 is root
Case two: 1 3 2 4 5   3 and 2 need to be swap, in this case node1 is pre, node2 is root
each case we found a mistake, we need to remember the root to satisfy this two cases

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

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-9-9 08:52:53 | 只看该作者
全局:
99. Iterative solution

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

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-9-9 10:15:31 | 只看该作者
全局:
108. Convert Sorted Array to Binary Search Tree
Recursive: mid as root node, split the array as left and right from mid.

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

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-9-9 11:28:56 | 只看该作者
全局:
501. Find Mode in Binary Search Tree
Solution using map

image.png (34.97 KB, 下载次数: 5)

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-9-9 11:29:46 | 只看该作者
全局:
微信用户_b99d1cc 发表于 2023-9-8 19:28
501. Find Mode in Binary Search Tree
Solution using map

or use in order traversal  to mark the same number of value
回复

使用道具 举报

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

本版积分规则

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