이분탐색
https://school.programmers.co.kr/learn/courses/30/lessons/43238
import java.util.*;
class Solution {
public long solution(int n, int[] times) {
long answer = 0;
int maxTime = Arrays.stream(times).max().getAsInt();
long left = 0;
long right = (long)maxTime * n;
while(left <= right) {
long mid = left + (right - left) / 2;
long passCnt = 0;
for(int time : times) {
passCnt += (mid / time);
}
if(passCnt < n) {
left = mid + 1;
} else {
right = mid - 1;
answer = mid;
}
}
return answer;
}
}
int maxTime = Arrays.stream(times).max().getAsInt();
long left = 0;
long right = (long)maxTime * n;
while(left <= right) {
long mid = left + (right - left) / 2;
long passCnt = 0;
for(int time : times) {
passCnt += (mid / time);
}
if(passCnt < n) {
left = mid + 1;
} else {
right = mid - 1;
answer = mid;
}
}
30분
값의 범위가 터무니없이 큰 경우 → 복잡도를 줄이기 위한 방법으로 이분 탐색을 고려할 것!