def solution(stones, k):
minimum = 0
maximum = 200000000
person = maximum // 2
while True:
# 건널 수 있나?
possible = True
cnt = 0
for i in stones :
if i < person :
cnt += 1
else :
cnt = 0
if cnt == k :
possible = False
break
# 건널 수 있으면
if possible :
minimum = person
next = (person + maximum) // 2
if person == next :
return person
person = next
# 건널 수 없으면
else :
maximum = person
next = (person + minimum) // 2
if person == next :
return person - 1
person = next
이진 탐색 오랜만에 하는거라 재밌었다 ㅋㅋㅋㅋ 곧 있으면 프로그래머스 1400점 갈듯
'컴퓨터 > 코테' 카테고리의 다른 글
릿코드 5 - Longest Palindromic Substring (0) | 2021.08.12 |
---|---|
프로그래머스 호텔 방 배정 (0) | 2021.08.12 |
프로그래머스 - 디스크 컨트롤러[heap] (0) | 2021.08.12 |
프로그래머스5 - 방의 개수 (0) | 2021.08.11 |
릿코드 3 - Longest Substring, 카카오 보석쇼핑 (0) | 2021.08.11 |