1212"""
1313# ===============================================================================
1414
15-
16- # Tree class definition
17- class TreeNode :
18- def __init__ (self , value ):
19-
20- self .val = value
21- self .left = None
22- self .right = None
15+ from algorithms .common .tree_node import TreeNode
2316
2417
2518# Function to validate if a binary tree is a BST
@@ -46,24 +39,24 @@ def validate_bst(node):
4639 if not valid_left or not valid_right :
4740 return (
4841 False ,
49- minn_left if minn_left else node .val ,
50- maxx_right if maxx_right else node .val ,
42+ minn_left if minn_left is not None else node .val ,
43+ maxx_right if maxx_right is not None else node .val ,
5144 )
5245
5346 # Check the current node's value against the max of the left subtree
5447 if maxx_left is not None and maxx_left > node .val :
5548 return (
5649 False ,
57- minn_left if minn_left else node .val ,
58- maxx_right if maxx_right else node .val ,
50+ minn_left if minn_left is not None else node .val ,
51+ maxx_right if maxx_right is not None else node .val ,
5952 )
6053
6154 # Check the current node's value against the min of the right subtree
6255 if minn_right is not None and minn_right < node .val :
6356 return (
6457 False ,
65- minn_left if minn_left else node .val ,
66- maxx_right if maxx_right else node .val ,
58+ minn_left if minn_left is not None else node .val ,
59+ maxx_right if maxx_right is not None else node .val ,
6760 )
6861
6962 # If all checks pass, the tree/subtree is a valid BST
0 commit comments