Download Maximum Depth of Binary Tree.py
# Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: def maxDepth(self, root): """ :type root: TreeNode :rtype: int """ if root is None: return 0 ld = self.maxDepth(root.left) rd = self.maxDepth(root.right) return 1 + max(ld, rd)
Leetcode 104 Maximum Depth of Binary Tree problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.
self.val = x
Feedback is the most important part of any website.
If you have any query, suggestion or feedback, Please feel free to contact us.