본문 바로가기

Algorithm120

LeetCode 700(Search in a Binary Search Tree, java) 0. 문제 https://leetcode.com/problems/search-in-a-binary-search-tree/ Search in a Binary Search 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 1. 문제 설명 - 문제에서 이진 탐색 트리(= root)와 정수(= val)가 주어진다. - 이진탐색트리를 탐색하는 과정에서 어떤 노드의 value가 주어진 정수(= val)와 동일한 경우를 찾는다. - 해당 노드의 모든 자식 노드를 반.. 2022. 4. 21.
LeetCode 112(Path Sum, java) 0. 문제 https://leetcode.com/problems/path-sum/ Path Sum - 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 1. 문제 설명 - 문제에서 이진트리(root)와 정수(targetSum)가 주어진다. - 루트 노드를 시작으로 단말 노드까지의 value를 합하여 targetSum을 만들 수 있는지 확인하는 것이 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - 우선 true를 반환하는 경우를 생각해보자. - 가장 먼저 생.. 2022. 4. 21.
LeetCode 226(Invert Binary Tree, java) 0. 문제 https://leetcode.com/problems/invert-binary-tree/ Invert 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 1. 문제 설명 - 문제에서 이진트리(root)가 주어진다. - 문제에서 주어진 이진트리(root)를 대칭한 모양으로 바꾸는 것이 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - 이 문제는 생각보다 간단하다. 루트 노드를 제외한 모든 자식 노드의 위치를 서로 변경하면 된다.. 2022. 4. 20.
LeetCode 101(Symmetric Tree, java) 0. 문제 https://leetcode.com/problems/symmetric-tree/ Symmetric 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 1. 문제 설명 - 문제에서 이진트리(root)가 주어진다. - 해당 이진트리의 모든 노드가 가진 값을 탐색 및 비교하여 대칭하는지를 판단하는 것이 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - 최초에 루트 노드가 가진 좌/우측 자식은 1개씩이므로, 이 둘의 value를 비교하면 대칭.. 2022. 4. 20.
LeetCode 104(Maximum Depth of Binary Tree, java) 0. 문제 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 1. 문제 설명 - 문제에서 이진트리(root)가 주어진다. - 이 이진트리를 탐색하여 이진트리의 깊이를 반환하는 것이 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - 이 문제는 이전에 풀어본 102번 문제에서 사용한 깊이 단위 탐색을 .. 2022. 4. 20.
LeetCode 102(Binary Tree Level Order Traversal, java) 0. 문제 https://leetcode.com/problems/binary-tree-level-order-traversal/ Binary Tree Level Order Traversal - 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 1. 문제 설명 - 문제에서 이진트리(root)가 주어진다. - 이진트리(root)를 깊이 단위로 탐색하며, 동일한 깊이에 있는 모든 노드를 하나의 배열로 묶는다. - 이렇게 깊이 단위로 묶인 각 배열을 하나의 배열 안에 넣어 .. 2022. 4. 19.
LeetCode 145(Binary Tree Postorder Traversal, java) 0. 문제 https://leetcode.com/problems/binary-tree-postorder-traversal/ Binary Tree Postorder Traversal - 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 1. 문제 설명 - 문제에서 이진트리(root)가 주어진다. - 해당 이진트리를 후위 순회 방식으로 탐색하여, 탐색한 순서대로 노드의 값을 배열에 담아 반환하는 것이 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - 후위 순회는 좌측 .. 2022. 4. 19.
LeetCode 94(Binary Tree In-order Traversal, java) 0. 문제 https://leetcode.com/problems/binary-tree-inorder-traversal/ Binary Tree Inorder Traversal - 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 1. 문제 설명 - 문제에서 이진트리(root)가 주어진다. - 주어진 이진트리를 중위 순회 순서로 탐색하여, 방문한 노드의 값을 배열에 담아 반환하는 것이 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - 우선 중위 순회는 좌측 자식.. 2022. 4. 19.
LeetCode 144(Binary Tree Preorder Traversal, java) 0. 문제 https://leetcode.com/problems/binary-tree-preorder-traversal/ Binary Tree Preorder Traversal - 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 1. 문제 설명 - 문제에서 이진트리(root)가 주어진다. - 이 문제는 이진트리를 전위 순회(Preorder)로 탐색하여 방문한 노드를 리스트로 반환하는 것이 핵심이다. - 이진 트리를 탐색하는 방법에는 3가지가 있다. → 전위 순회(.. 2022. 4. 18.