mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-07 11:37:36 +08:00
Make some ruff fixes (#8154)
* Make some ruff fixes * Undo manual fix * Undo manual fix * Updates from ruff=0.0.251
This commit is contained in:
@ -60,7 +60,7 @@ class BinarySearchTree:
|
||||
else: # Tree is not empty
|
||||
parent_node = self.root # from root
|
||||
if parent_node is None:
|
||||
return None
|
||||
return
|
||||
while True: # While we don't get to a leaf
|
||||
if value < parent_node.value: # We go left
|
||||
if parent_node.left is None:
|
||||
|
@ -37,7 +37,7 @@ def preorder(root: Node | None) -> list[int]:
|
||||
>>> preorder(make_tree())
|
||||
[1, 2, 4, 5, 3]
|
||||
"""
|
||||
return [root.data] + preorder(root.left) + preorder(root.right) if root else []
|
||||
return [root.data, *preorder(root.left), *preorder(root.right)] if root else []
|
||||
|
||||
|
||||
def postorder(root: Node | None) -> list[int]:
|
||||
@ -55,7 +55,7 @@ def inorder(root: Node | None) -> list[int]:
|
||||
>>> inorder(make_tree())
|
||||
[4, 2, 5, 1, 3]
|
||||
"""
|
||||
return inorder(root.left) + [root.data] + inorder(root.right) if root else []
|
||||
return [*inorder(root.left), root.data, *inorder(root.right)] if root else []
|
||||
|
||||
|
||||
def height(root: Node | None) -> int:
|
||||
|
@ -50,7 +50,7 @@ def inorder(node: None | BinaryTreeNode) -> list[int]: # if node is None,return
|
||||
"""
|
||||
if node:
|
||||
inorder_array = inorder(node.left_child)
|
||||
inorder_array = inorder_array + [node.data]
|
||||
inorder_array = [*inorder_array, node.data]
|
||||
inorder_array = inorder_array + inorder(node.right_child)
|
||||
else:
|
||||
inorder_array = []
|
||||
|
@ -319,9 +319,8 @@ class RedBlackTree:
|
||||
"""A helper function to recursively check Property 4 of a
|
||||
Red-Black Tree. See check_color_properties for more info.
|
||||
"""
|
||||
if self.color == 1:
|
||||
if color(self.left) == 1 or color(self.right) == 1:
|
||||
return False
|
||||
if self.color == 1 and 1 in (color(self.left), color(self.right)):
|
||||
return False
|
||||
if self.left and not self.left.check_coloring():
|
||||
return False
|
||||
if self.right and not self.right.check_coloring():
|
||||
|
Reference in New Issue
Block a user