Leetcode/python/104_maximum_depth_of_binary_tree.py

6 lines
195 B
Python
Raw Normal View History

2024-04-30 15:56:00 +00:00
class Solution:
def maxDepth(self, root: Optional[TreeNode]) -> int:
if root is None:
return 0
return max(self.maxDepth(root.left), self.maxDepth(root.right)) + 1