File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed
Contents/07.Tree/02.Binary-Search-Tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -130,8 +130,8 @@ class Solution:
130
130
131
131
1 . 如果当前节点为空,则返回当前节点。
132
132
2 . 如果当前节点值大于 ` val ` ,则递归去左子树中搜索并删除,此时 ` root.left ` 也要跟着递归更新。
133
- 3 . 如果当前节点值小于 ` key ` ,则递归去右子树中搜索并删除,此时 ` root.right ` 也要跟着递归更新。
134
- 4 . 如果当前节点值等于 ` key ` ,则该节点就是待删除节点。
133
+ 3 . 如果当前节点值小于 ` val ` ,则递归去右子树中搜索并删除,此时 ` root.right ` 也要跟着递归更新。
134
+ 4 . 如果当前节点值等于 ` val ` ,则该节点就是待删除节点。
135
135
1 . 如果当前节点的左子树为空,则删除该节点之后,则右子树代替当前节点位置,返回右子树。
136
136
2 . 如果当前节点的右子树为空,则删除该节点之后,则左子树代替当前节点位置,返回左子树。
137
137
3 . 如果当前节点的左右子树都有,则将左子树转移到右子树最左侧的叶子节点位置上,然后右子树代替当前节点位置。
@@ -140,15 +140,15 @@ class Solution:
140
140
141
141
``` Python
142
142
class Solution :
143
- def deleteNode (self , root : TreeNode, key : int ) -> TreeNode:
143
+ def deleteNode (self , root : TreeNode, val : int ) -> TreeNode:
144
144
if not root:
145
145
return root
146
146
147
- if root.val > key :
148
- root.left = self .deleteNode(root.left, key )
147
+ if root.val > val :
148
+ root.left = self .deleteNode(root.left, val )
149
149
return root
150
- elif root.val < key :
151
- root.right = self .deleteNode(root.right, key )
150
+ elif root.val < val :
151
+ root.right = self .deleteNode(root.right, val )
152
152
return root
153
153
else :
154
154
if not root.left:
You can’t perform that action at this time.
0 commit comments