def calc(stones, k, mid):
now = 0
for stone in stones:
if stones < mid:
now += 1
else:
now = 0
if now >= k :
return False
return True
def solution(stones, k):
left, right = 1, max(stones)+1
while left < (right-1):
mid = (left+right) //2
if calc(stones, k, mid):
left = mid
else:
right = mid
return left
기존 나의 풀이는 통과는 되지만, 효율성 측면에서 탈락이었다.
def mysolution(stones, k):
answer = 0
go = 1
print(stones)
while(go):
j = 0
for i in range(len(stones)):
if i == len(stones):
break
if j == k:
go = 0
return answer
if stones[i] == 0:
j += 1
stones[i] = 0
else:
stones[i] -= 1
j = 0
print('complete', answer + 1, 'people')
print(stones)
answer += 1
return answer