반응형 분류 전체보기128 [DSA][Trees] 10. Count Good Nodes in Binary Tree LeetCode 1448 10. Count Good Nodes in Binary TreeGiven a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X.Return the number of good nodes in the binary tree. [질문하기]- 경로상 최댓값과 현재 노드의 값이 같은 경우에도 good node인가요? - 노드 값은 양수인가요? NO [아이디어]- 재귀 함수를 사용하여 현재 노드와 maxVal을 비교하여 카운트한다. [풀이 1] Depth First Searchclass Solution: .. 2025. 7. 19. [DSA][Trees] 09. Binary Tree Right Side View LeetCode 199 09. Binary Tree Right Side ViewGiven the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. [질문하기]- root가 null일 경우 빈 리스트를 반환하나요? [아이디어]- BFS 방식으로 트리를 순회하면서, 각 노드를 큐(deque)에 저장해 레벨 단위로 탐색한다. [풀이 1] Breadth First Searchclass Solution: def rightSideView(self, root: Optional[TreeNode]) -> .. 2025. 7. 18. [DSA][Trees] 08. Binary Tree Level Order Traversal LeetCode 102 08. Binary Tree Level Order TraversalGiven the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level). [질문하기]- root가 null일 경우 빈 리스트를 반환하나요? [아이디어]- BFS 방식으로 트리를 순회하면서, 각 노드를 큐(deque)에 저장해 레벨 단위로 탐색한다. [풀이 1] Breadth First Searchclass Solution: def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]: .. 2025. 7. 17. [DSA][Trees] 07. Lowest Common Ancestor of a Binary Search Tree LeetCode 235 07. Lowest Common Ancestor of a Binary Search TreeGiven a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST.According to the definition of LCA on Wikipedia:“The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself).”.. 2025. 7. 16. 이전 1 ··· 8 9 10 11 12 13 14 ··· 32 다음