thiagowfx's avatar

Β¬ just serendipity πŸ€ (not just serendipity)

LeetCode #104: Maximum Depth of Binary Tree

β€’ 54 words β€’ 1 min

LeetCode #104: Maximum Depth of Binary Tree:

python
# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def maxDepth(self, root: Optional[TreeNode]) -> int:
        if not root:
            return 0

        return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right))