반응형 분류 전체보기128 [DSA][Trees] 14. Binary Tree Maximum Path Sum LeetCode 124 14. Binary Tree Maximum Path SumA path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them.A node can only appear in the sequence at most once.Note that the path does not need to pass through the root.The path sum of a path is the sum of the node's values in the path.Given the root of a binary tree, return the maximum.. 2025. 7. 26. [DSA][Trees] 13. Construct Binary Tree from Preorder and Inorder Traversal LeetCode 105 13. Construct Binary Tree from Preorder and Inorder TraversalGiven two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, construct and return the binary tree. [질문하기]- Binary Tree의 노드의 값 중 중복된 값이 있나요? NO [아이디어]- preorder와 inorder의 순회 방식을 통해 root / left / right 세 구역으로 나누고, 재귀를 통해 Binary.. 2025. 7. 26. [DSA][Trees] 12. Kth Smallest Element in a BST LeetCode 230 12. Kth Smallest Element in a BSTGiven the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree. [질문하기]- k는 항상 노드의 개수보다 작거나 같나요? YES [아이디어]- Inorder로 값을 저장한 후 k번째 값을 반환하자 [풀이 1] Depth First Search - Inorder Traversalclass Solution: def kthSmallest(self, root: Optional[TreeNode], k: int) -> int: .. 2025. 7. 23. [DSA][Trees] 11. Validate Binary Search Tree LeetCode 98 11. Validate Binary Search TreeGiven the root of a binary tree, determine if it is a valid binary search tree (BST).A valid BST is defined as follows:- The left subtree of a node contains only nodes with keys less than the node's key.- The right subtree of a node contains only nodes with keys greater than the node's key.- Both the left and right subtrees must also be binary search tr.. 2025. 7. 20. 이전 1 ··· 7 8 9 10 11 12 13 ··· 32 다음