#104
Maximum Depth of Binary Tree
easy· Treesruns: 0Given the root of a binary tree, return its maximum depth. The maximum depth is the number of nodes along the longest path from the root down to the farthest leaf.
sign in to paste and practice your own solution
wpm 0acc 100%time 0:000 / 188
class Solution:
def maxDepth(self, root: TreeNode | None) -> int:
if not root:
return 0
return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right))
click the box to focus · tab inserts 4 spaces · backspace to correct · esc to pause
desktop only
codedrill is a typing game and needs a real keyboard. open this on a laptop or desktop to practice.
you can still browse problems and sections from your phone.