본문 바로가기

Algorithm120

LeetCode 189(Rotate Array, java) 0. 문제 https://leetcode.com/problems/rotate-array/ Rotate Array - 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)과 반복 횟수(k)가 주어진다. - 주어진 배열의 원소를 k만큼 우측으로 한 칸씩 이동시키는 것이 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - 이 문제가 까다로운 이유는 문제에서 주어진 메서드가 void 타입이라는 것이다. - 즉, 반환형이.. 2022. 4. 24.
LeetCode 977(Squares of a Sorted Array, java) 0. 문제 https://leetcode.com/problems/squares-of-a-sorted-array/ Squares of a Sorted Array - 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)이 주어진다. - 정수형 배열의 모든 요소의 제곱을 배열에 저장하고 이를 오름차순으로 반환하는 것이 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - 가장 간단한 해결 방법은 for문을 사용하여 원소.. 2022. 4. 24.
LeetCode 35(Search Insert Position, java) 0. 문제 https://leetcode.com/problems/search-insert-position/ Search Insert Position - 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)가 주어진다. - 배열을 탐색하면서 target이 존재한다면 target의 index를 반환한다. - 만약 target이 없다면 target이 있어야 하는 위치의 index를 반환.. 2022. 4. 23.
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.