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

[高频题] 记录贴,互勉

🔗
 楼主| 微信用户_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, 下载次数: 6)

image.png
回复

使用道具 举报

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

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

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, 下载次数: 6)

image.png
回复

使用道具 举报

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

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

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, 下载次数: 6)

image.png
回复

使用道具 举报

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

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

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
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-9-9 12:08:51 | 只看该作者
全局:
450. Delete Node in a BST
Recursive solution:
1. Find the key
2. replace the target key value
3. delete the replaced value's node

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

image.png
回复

使用道具 举报

🔗
 楼主| 微信用户_b99d1cc 2023-9-9 12:48:24 | 只看该作者
全局:
133. Clone Graph
1. copy   (Map old to new)
2. connect (From map find the old node's neighbor for new node)

评分

参与人数 1大米 +1 收起 理由
speed_secret20 + 1 给你点个赞!加油!

查看全部评分

回复

使用道具 举报

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

本版积分规则

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