목록Binary Search (3)
N
https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/description/ Capacity To Ship Packages Within D Days - LeetCode Can you solve this real interview question? Capacity To Ship Packages Within D Days - A conveyor belt has packages that must be shipped from one port to another within days days. The ith package on the conveyor belt has a weight of weights[i]. Each day, we leetcod..
https://school.programmers.co.kr/learn/courses/30/lessons/12984 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr function solution(land, P, Q) { // variables and functions const N = land.length; const arr = []; let answer = Infinity; const getCost = (height, arr) => { let cost = 0; for(let i = 0; i < arr.length; i++){ if(height < arr[..

이분탐색을 통해 문제 해결. 처음에는 완전탐색으로 시도했지만 효율성 테스트를 통과하지 못하므로, 이분탐색으로 문제를 풀었다. front = 1, back = stones 배열에서의 max 값으로 초기화한다. front = k가 된다면 true를 리턴하여 back = mid - 1을 해주도록 한다. false가 반환되면 front = mid + 1. 결국 front가 징검다리를 건널 수 있는 친구의 수가 된다. #include #include #include using namespace std; bool bs(vector stones, int mid, int k) { int count = 0; for(int i = 0; i < stones.size(); i++) { if(stones[i] - mid = k..