Home Maximum Depth of Binary Tree
Post
Cancel

Maximum Depth of Binary Tree

Leetcode Problem

Maximum Depth of Binary Tree

binary tree의 최대 깊이를 구하는 문제입니다.

1
2
3
4
class Solution:
    def maxDepth(self, root: Optional[TreeNode]) -> int:
        return max(self.maxDepth(root.left) + 1, self.maxDepth(root.right) + 1) if root else 0

이전에 배운 지식을 활용하여 한 줄로 문제를 해결할 수 있었습니다.





참고

This post is licensed under CC BY 4.0 by the author.