본문 바로가기
Beakjoon&프로그래머스/파이썬

[백준/파이썬]13777번 Hunt The Rabbit

by 현장 2021. 10. 8.

-코드

def binary(start, end, target, lst):
    result = []
    while start <= end:
        mid = (start + end) // 2
        if lst[mid] == target:
            result.append(lst[mid])
            return result
        elif lst[mid] <= target:
            result.append(lst[mid])
            start = mid + 1
        else:
            result.append(lst[mid])
            end = mid - 1


arr = [i for i in range(1, 51)]
while 1:
    n = int(input())
    if n == 0:
        break
    print(*binary(0, len(arr) - 1, n, arr))