Skip to content

Commit 13d22f2

Browse files
authored
Update red_black_tree.py
1 parent 108aa90 commit 13d22f2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

data_structures/binary_tree/red_black_tree.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff 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 (

0 commit comments

Comments
 (0)