목록이진 탐색 (3)
N
https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/ Find First and Last Position of Element in 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 이진 탐색 알고리즘 활용. 주어진 nums에서 target을 찾고, 해당 인덱스의 처음과 끝을 answer에 저장하면 된다. 만약 nums가 비어있다면 바로 리..
https://programmers.co.kr/learn/courses/30/lessons/12982 코딩테스트 연습 - 예산 S사에서는 각 부서에 필요한 물품을 지원해 주기 위해 부서별로 물품을 구매하는데 필요한 금액을 조사했습니다. 그러나, 전체 예산이 정해져 있기 때문에 모든 부서의 물품을 구매해 줄 수는 programmers.co.kr 최대한 많은 부서에 예산을 줘야하기 때문에 주어진 d 배열을 오름차순으로 정렬한다. 이후 이진 탐색을 진행. 0 ~ mid 인덱스까지의 예산을 더하여 budget보다 작을 때까지의 front 값을 찾아 리턴하면 된다. const binarySearch = (d, mid, budget) => { let sum = 0; for(let i = 0; i budget){ r..
374. Guess Number Higher or Lower We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you guess wrong, I will tell you whether the number I picked is higher or lower than your guess. You call a pre-defined API int guess(int num), which returns 3 possible results: -1: The number I picked is lower than your guess (..