Notice
Recent Posts
Recent Comments
Link
오늘도 개발
52. Maximum Depth of Binary Tree(DFS) 본문
문제
이진트리의 루트를 받아 최대 깊이를 계산하시오.

Input: root = [3,9,20,null,null,15,7]
Output: 3
해결 방식
dfs 사용.
class Solution:
def maxDepth(self, root: Optional[TreeNode]) -> int:
if not root:
return 0
return max(self.maxDepth(root.left), self.maxDepth(root.right)) + 1'자료구조 & 알고리즘 > Leetcode' 카테고리의 다른 글
| 53. Find if Path Exists in Graph(BFS, DFS) (0) | 2022.12.23 |
|---|---|
| 51. Binary Tree Level Order Traversal(BFS) (0) | 2022.11.29 |
| 50. Kth Largest Element in a Stream(Heap) (0) | 2022.11.16 |
| 47, 48, 49. Binary Tree Traversal(inorder, preorder, postorder) (0) | 2022.11.14 |
| 46. Insert into a Binary Search Tree (0) | 2022.11.12 |