Skip to content

Commit 9aeb99d

Browse files
author
Eric
committed
94차 3번 문제풀이
1 parent da4787f commit 9aeb99d

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

live9/test94/문제3/황장현.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function solution(stones, k) {
2+
let min = 1;
3+
let max = 200000000;
4+
5+
while (min <= max) {
6+
const mid = Math.floor((min + max) / 2);
7+
let cnt = 0;
8+
for (let stone of stones) {
9+
if (stone - mid <= 0) cnt++;
10+
else cnt = 0;
11+
12+
if (cnt === k) break;
13+
}
14+
if (cnt === k) max = mid - 1;
15+
else min = mid + 1;
16+
}
17+
return min;
18+
}
19+
20+
console.log(solution([2, 4, 5, 3, 2, 1, 4, 2, 5, 1], 3));

0 commit comments

Comments
 (0)