티스토리 뷰

반응형

오랜만에 푸니 잘 안풀린다. 쎈이라 생각하고 금두완을 다시 이행하다


def solution(distance, rocks, n):
    low = 1
    if len(rocks) - n == 0:
        return distance
    import math
    rocks.append(distance)
    midVisit = []
    rocks.sort()
    answer = 0
    high = math.ceil(distance / (len(rocks) - n))
    while low <= high:

        mid = (low + high) // 2
        # print("ans", answer, mid, midVisit)

        if mid in midVisit:
            break
        else:
            midVisit.append(mid)
        jumpCount = 0
        before = 0
        index = 0

        while index < len(rocks):
            if rocks[index] - before < mid:
                index += 1
                jumpCount += 1
                continue
            else:
                before = rocks[index]
                index += 1
        if jumpCount > n:
            high = mid + 1
        elif jumpCount <= n:
            if answer > mid:
                break
            else:
                answer = mid
                low = mid - 1

    return answer
반응형
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함