Skip to content

Commit 6405779

Browse files
author
hangyeol
committed
94차 3번 문제풀이
1 parent 3d56dd3 commit 6405779

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

live9/test94/문제3/백한결.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
def solution(stones, k):
2+
start = 0
3+
end = len(stones) - 1
4+
max_friends = 0
5+
6+
while start <= end:
7+
mid = (start + end) // 2
8+
9+
if checkUnderZero(stones, k, mid):
10+
max_friends = mid
11+
start = mid + 1
12+
else:
13+
end = mid - 1
14+
15+
return max_friends
16+
17+
18+
# 징검다리 수에서 건너는 사람 수를 빼서 연속된 0이하의 수가 k를 초과하는지 검사
19+
def checkUnderZero(stones, k, friends):
20+
count = 0
21+
22+
for stone in stones:
23+
if stone - friends <= 0:
24+
count += 1
25+
else:
26+
count = 0
27+
28+
if count >= k:
29+
return False
30+
31+
return True
32+
33+
34+
print(checkUnderZero([2, 4, 5, 3, 2, 1, 4, 2, 5, 1], 3, 2))

0 commit comments

Comments
 (0)