Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 1.05 KB

_104. Maximum Depth of Binary Tree.md

File metadata and controls

39 lines (29 loc) · 1.05 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : July 04, 2024

Last updated : July 04, 2024


Related Topics : Tree, Depth-First Search, Breadth-First Search, Binary Tree

Acceptance Rate : 76.6 %


Solutions

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))