104. Maximum Depth of Binary Tree
My accepted Python solution to LeetCode problem 104, Maximum Depth of Binary Tree, running in 3ms.
- Difficulty: Easy
- Python
- Runtime 3ms
- Memory 15MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 3ms, memory 15MB, accepted 2025-12-23.
class Solution(object):
def maxDepth(self, root):
if not root:
return 0
return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right))