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:
231
231
True
232
232
"""
233
233
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
+
235
239
value = self .left .get_max ()
236
240
if value is not None :
237
241
self .label = value
@@ -268,10 +272,7 @@ def remove(self, label: int) -> RedBlackTree:
268
272
elif self .right :
269
273
self .right .remove (label )
270
274
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
+
275
276
def _remove_repair (self ) -> None :
276
277
"""Repair the coloring after removal."""
277
278
if (
You can’t perform that action at this time.
0 commit comments