⬅ Previous Topic
Delete a Node in a Binary Search TreeNext Topic ⮕
Find the Maximum Value in a Binary Search Tree⬅ Previous Topic
Delete a Node in a Binary Search TreeNext Topic ⮕
Find the Maximum Value in a Binary Search TreeTopic Contents
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def findMin(root):
if not root:
return None
while root.left:
root = root.left
return root.val
if __name__ == '__main__':
# Construct BST:
# 5
# / \
# 3 7
# / \ / \
# 2 4 6 8
root = TreeNode(5, TreeNode(3, TreeNode(2), TreeNode(4)), TreeNode(7, TreeNode(6), TreeNode(8)))
print(findMin(root))
⬅ Previous Topic
Delete a Node in a Binary Search TreeNext Topic ⮕
Find the Maximum Value in a Binary Search TreeYou can support this website with a contribution of your choice.
When making a contribution, mention your name, and programguru.org in the message. Your name shall be displayed in the sponsors list.