/ trees
7 Questions Completed
Balanced Binary Tree
Invert Binary Tree
Maximum Depth Of Binary Tree
Same Tree
Subtree Of Another Tree
All Nodes Distance K In Binary Tree
Binary Tree Right Side View
Memorized from my COMPSCI 2C03 notes haha.
class Solution: def maxDepth(self, root: Optional[TreeNode]) -> int: if not root: return 0 return max(self.maxDepth(root.right), self.maxDepth(root.left)) + 1
This function recursively calls height until we reach the traversal of the null nodes. ‘height()’ will return a value, so that is used in the outer recursive call as a value as seen below.