LeetCode 269

Tree: 110. Balanced Binary Tree

110. Balanced Binary Tree # Definition for a binary tree node.# class TreeNode:# def __init__(self, val=0, left=None, right=None):# self.val = val# self.left = left# self.right = rightclass Solution: def isBalanced(self, root: Optional[TreeNode]) -> bool: # 높이 균형 이진 트리는 각 노드의 두 서브 트리의 깊이가 1 이상 차이가 나지 않는 이진 트리입니다. # height-balanced tree: 높이 균형 이진 트리는, ..

Tree: 543. Diameter of Binary Tree ★

543. Diameter of Binary Tree 트리의 Diameter 즉, 지름을 구하려면,어떤 노드를 기준으로, 좌측 최장 길이+오른쪽 최장 길이..꼭. 이 노드가 root 가 아닐 수도 있음: The path does not necessarily have to pass through the root.위 의 경우, 노드 3을 기준으로, 왼쪽 2, 오른쪽 2... 그래서 diameter 는 2+2=4 임 따라서,전역 변수 max_length 만들고, 모든 노드를 탐색하면서, 왼쪽+오른쪽 길이, 즉, max_lengh를 계속 업데이트 해야함. 모든 노드 탐색시, dfs,,,로 # Definition for a binary tree node.# class TreeNode:# def __init_..

DFS: 111. Minimum Depth of Binary Tree

111. Minimum Depth of Binary Tree if not root: 루트 비어 있는 경우    return 0 : 깊이는 0 root 부터, 깊이는 1 자식이 둘다 없으면 leaf 노드 임if not node.left and not node.right:   return 깊이 최소 값 업데이트 # Definition for a binary tree node.# class TreeNode:# def __init__(self, val=0, left=None, right=None):# self.val = val# self.left = left# self.right = rightclass Solution: def minDepth(self, r..