binary tree2 [LeetCode] Diameter of Binary Tree (이진트리 가장 긴 경로) https://leetcode.com/problems/diameter-of-binary-tree/ Diameter of Binary Tree - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com class Solution: longest: int = 0 def diameterOfBinaryTree(self, root: Optional[TreeNode]) -> int: def dfs(node): if not node: return -1 left = dfs(node.l.. 2022. 4. 8. [LeetCode] Maximum Depth of Binary Tree (이진트리 최대 깊이 구하기) https://leetcode.com/problems/maximum-depth-of-binary-tree/ Maximum Depth of Binary Tree - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 트리에서 깊이(Depth)는 루트에서부터 현재 노드까지의 거리이다. 최대 깊이는 리프 노드까지 거리 중 가장 긴 거리를 구하면 된다. 재귀 방식 # Definition for a binary tree node. # class TreeNode: # def _.. 2022. 4. 8. 이전 1 다음