본문 바로가기

Algorithm/알고리즘 문제풀이92

LeetCode 278(First Bad Version, java) 0. 문제 https://leetcode.com/problems/first-bad-version/ First Bad Version - 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. 문제 설명 - 문제에서 제품의 개수(= n)가 주어진다. - 모든 제품은 이전 버전의 제품을 기반으로 생성된다. - 그러므로 이전 버전이 잘못된 경우, 이를 기반으로 만들어진 다음 버전 또한 잘못된 제품이 된다. - 문제에서 isBadVersion(int version) 이라는 .. 2022. 4. 23.
LeetCode 704(Binary Search, java) 0. 문제 https://leetcode.com/problems/binary-search/ Binary Search - 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. 문제 설명 - 문제에서 정수로 이루어진 배열(nums)과 찾는 수(target)가 주어진다. - O(log n)의 시간 복잡도로 탐색을 수행하여 배열에 있는 target의 존재 유무를 파악하는 것이 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - O(log n)의 시간 복잡도로 탐색을.. 2022. 4. 23.
LeetCode 235(Lowest Common Ancestor of a Binary Search Tree, java) 0. 문제 https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/ Lowest Common Ancestor of 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)와 두 개의 노드(p, q)가 주어진다. - 주어진 두 개의 노드(p, q) 사이에 존재하는 노드 중 가장 작은 값을 가지는 노.. 2022. 4. 22.
LeetCode 653(Two Sum IV - Input is a BST, java) 0. 문제 https://leetcode.com/problems/two-sum-iv-input-is-a-bst/ Two Sum IV - Input is a BST - 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)와 찾는 수(k)가 주어진다. - 트리를 구성하는 노드 중 2개 노드의 value 합이 찾는 수인 경우가 존재하는지 판단하는 것이 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - 우선 모든 .. 2022. 4. 22.
LeetCode 98(Validate Binary Search Tree, java) 0. 문제 https://leetcode.com/problems/validate-binary-search-tree/ Validate 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)가 주어진다. - 주어진 이진트리가 이진 탐색 트리를 만족하는지 판단하는 것이 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - 이 문제는 이진 탐색 트리의 조건을 만족하는지를 판단하는 문제다. .. 2022. 4. 22.
LeetCode 701(Insert into a Binary Search Tree, java) 0. 문제 https://leetcode.com/problems/insert-into-a-binary-search-tree/ Insert into 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)가 주어진다. - 이 문제는 문제에서 주어진 정수(= val)를 이진탐색트리에 삽입하는 것이 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - 이진 탐색 트리.. 2022. 4. 21.
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.