We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4ecdfb5 commit 5948c51Copy full SHA for 5948c51
250217/PG_징검다리건너기.java
@@ -0,0 +1,39 @@
1
+/**
2
+ * 프로그래머스 징검다리 건너기
3
+ * - 매개변수 탐색
4
+ * - 0이 k-1개 연속으로 나와야 건널 수 있음
5
+ */
6
+
7
+class Solution {
8
+ public int solution(int[] stones, int k) {
9
+ int answer = 0;
10
11
+ int left = Integer.MAX_VALUE;
12
+ int right = Integer.MIN_VALUE;
13
14
+ for (int stone : stones) {
15
+ left = Math.min(left, stone);
16
+ right = Math.max(right, stone);
17
+ }
18
19
+ while (left <= right) {
20
+ int mid = left + (right - left) / 2;
21
22
+ int zeroCount = 0;
23
24
25
+ if (stone - mid <= 0) zeroCount++;
26
+ else zeroCount = 0;
27
28
+ if (zeroCount >= k) break;
29
30
31
+ if (zeroCount < k) {
32
+ answer = mid;
33
+ left = mid + 1;
34
+ } else right = mid - 1;
35
36
37
+ return left;
38
39
+}
0 commit comments