반응형 분류 전체보기128 [DSA][Trees] 03. Diameter of Binary Tree LeetCode 543 03. Diameter of Binary TreeGiven the root of a binary tree, return the length of the diameter of the tree.The diameter of a binary tree is the length of the longest path between any two nodes in a tree.This path may or may not pass through the root.The length of a path between two nodes is represented by the number of edges between them. [질문하기]- 빈 트리(루트가 None)인 경우 diameter는 0으로 처리하.. 2025. 7. 12. [DSA][Trees] 02. Maximum Depth of Binary Tree LeetCode 104 02. Maximum Depth of Binary TreeGiven the root of a binary tree, return its maximum depth.A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. [질문하기]- 빈 트리(루트가 None)인 경우 깊이는 0으로 처리하나요? [아이디어]- BFS를 사용하여 level을 구하자 [풀이 1] Breadth First Searchclass Solution: def maxDepth(self, root: Optional[TreeNode]) -> .. 2025. 7. 10. [DSA][Trees] 01. Invert Binary Tree LeetCode 226 01. Invert Binary TreeGiven the root of a binary tree, invert the tree, and return its root. [질문하기]- 루트 노드가 None일 수 있나요? 그런 경우에는 None을 그대로 반환하나요? [아이디어]- 재귀를 이용해서 각 노드의 자식 노드를 순차적으로 탐색하고 왼쪽과 오른쪽 자식을 서로 바꿔준다. [풀이 1] Depth First Searchclass Solution: def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]: if not root: return None self.invertTree(root... 2025. 7. 9. [DSA][Linked List] 11. Reverse Nodes in k-Group LeetCode 25 11. Reverse Nodes in k-GroupGiven the head of a linked list, reverse the nodes of the list k at a time, and return the modified list.k is a positive integer and is less than or equal to the length of the linked list.If the number of nodes is not a multiple of k then left-out nodes, in the end, should remain as it is.You may not alter the values in the list's nodes, only nodes themsel.. 2025. 7. 8. 이전 1 ··· 10 11 12 13 14 15 16 ··· 32 다음