바이너리 서치에 대해서 배웠습니다.

생각보다 간단하네요 ㅎㅎ

class Solution:
    def searchInsert(self, nums: List[int], target: int) -> int:
        if not nums:
            return 0
        def search(nums, target, l, r):
            while l <= r:
                m = (l+r)//2
                if nums[m] == target:
                    return m
                if nums[m] < target:
                    l = m+1
                else:
                    r = m-1
            return l
    
        return search(nums, target, 0, len(nums)-1)

Posted by 공놀이나하여보세
,