Lintcode87 Remove Node In Binary Search Treesolution 题解
来源:互联网 发布:adobe encoder mac 编辑:程序博客网 时间:2024/06/06 03:03
【题目描述】
Given a root of Binary Search Tree with unique value for each node. Remove the node with given value. If there is no such a node with given value in the binary search tree, do nothing. You should keep the tree still a binary search tree after removal.
给定一棵具有不同节点值的二叉查找树,删除树中与给定值相同的节点。如果树中没有相同值的节点,就不做任何处理。你应该保证处理之后的树仍是二叉查找树。
【题目链接】
www.lintcode.com/en/problem/remove-node-in-binary-search-tree/
【题目解析】
首先根据BST(二叉查找树)的性质,找到目标节点cur及其父节点pre
如果cur不存在,则直接返回root。记ncur为取代cur位置的节点,默认令ncur = cur.right。如果cur拥有左孩子,则将其右孩子链接到左孩子的最大子节点的右侧,令cur = cur.left。然后修正pre与ncur之间的关系。
【参考答案】
www.jiuzhang.com/solutions/remove-node-in-binary-search-tree/
阅读全文
0 0
- Lintcode87 Remove Node In Binary Search Treesolution 题解
- Lintcode87 Remove Node In Binary Search Treesolution 题解
- Remove Node in Binary Search Tree
- Lintcode - Remove Node in Binary Search Tree
- [刷题]Remove Node in Binary Search Tree
- lintcode:Remove Node in Binary Search Tree
- Remove Node in Binary Search Tree
- Lintcode85 Insert Node In A Binary Search Tree solution 题解
- Insert Node in a Binary Search Tree
- Insert Node in a Binary Search Tree
- Lintcode11 Search Range in Binary Search Tree solution 题解
- LeetCode 题解(264) : Verify Preorder Sequence in Binary Search Tree:
- [刷题]Insert Node in a Binary Search Tree
- lintcode: Insert Node in a Binary Search Tree
- #85 Insert Node in a Binary Search Tree
- Unique Binary Search Trees题解
- binary search in STL
- LintCode Insert a Node in a Binary Search Tree 在二叉查找树中插入节点
- rem
- PLSA主题模型的EM算法推导
- HFOI2017.7.15校内赛(普及组)题解
- Machine Learning 之 Types of Learning
- [记录]Java虚拟机 - 待续
- Lintcode87 Remove Node In Binary Search Treesolution 题解
- 携程Android App插件化和动态加载实践
- jenkins上的常用插件
- 基于贪心算法的几类区间覆盖问题:(侵删)
- 【shell】grep命令及常见用法
- Intellij Idea2017模块管理
- 阿里云申请的免费证书,配置到Tomcat,实现https访问
- 每日一刷——删除无头链表非尾结点&倒序打印链表
- scala不使用new关键字创建对象实例