Algorithm/programmers

징검다리 건너기 ( Level 3, Python, 2019 카카오 개발자 겨울 인턴십 )

takeU 2022. 9. 15. 06:21
반응형
def solution(stones, k):
    left, right = 1, 200000000
    while left <= right:
        print(left, right)
        mid = (left + right) // 2
        count = 0
        for s in stones:
            if s <= mid:
                count += 1
                if count >= k:
                    break
            else:
                count = 0
        if count >= k:
            right = mid - 1
        else:
            left = mid + 1

    return left

이분탐색