Created
August 5, 2023 08:31
-
-
Save ponnamkarthik/62bc67ab7261e992fb16583264e259b4 to your computer and use it in GitHub Desktop.
Maximum Depth of Binary Tree - Recursion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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