Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ponnamkarthik/62bc67ab7261e992fb16583264e259b4 to your computer and use it in GitHub Desktop.
Save ponnamkarthik/62bc67ab7261e992fb16583264e259b4 to your computer and use it in GitHub Desktop.
Maximum Depth of Binary Tree - Recursion
# 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.right), self.maxDepth(root.right))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment