# Programmers
# (LV.3) 이분탐색 (opens new window)
function solution(n, times) {
let low = 1;
let high = 12345678901234567890;
let mid = 0;
let ans = 12345678901234567890;
while (low <= high) {
mid = parseInt((low + high) / 2);
const ssum = times.reduce((prev, cur) => {
prev = prev + parseInt(mid / cur);
return prev;
}, 0);
if (ssum >= n) {
high = mid - 1;
ans = Math.min(mid, ans);
} else if (ssum < n) {
low = mid + 1;
}
}
return ans;
}
← Programmers vscode →