File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
data_structures/binary_tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -231,7 +231,11 @@ def remove(self, label: int) -> RedBlackTree:
231231 True
232232 """
233233 if self .label == label :
234- if self .left and self .right :
234+ if self .left and self .right :
235+ # It's easier to balance a node with at most one child,
236+ # so we replace this node with the greatest one less than
237+ # it and remove that.
238+
235239 value = self .left .get_max ()
236240 if value is not None :
237241 self .label = value
@@ -268,10 +272,7 @@ def remove(self, label: int) -> RedBlackTree:
268272 elif self .right :
269273 self .right .remove (label )
270274 return self .parent or self
271- # It's easier to balance a node with at most one child,
272- # so we replace this node with the greatest one less than
273- # it and remove that.
274-
275+
275276 def _remove_repair (self ) -> None :
276277 """Repair the coloring after removal."""
277278 if (
You can’t perform that action at this time.
0 commit comments