<reponame>minyong-jeong/hello-algorithm<filename>leetcode/35.py
"""
    https://leetcode.com/problems/search-insert-position/
    35. Search Insert Position (Easy)

    [풀이방법]
    Binary Search
"""

class Solution(object):
    def searchInsert(self, nums, target):
        start = 0
        end = len(nums) - 1
        
        if target > nums[end]:
            return len(nums)
        
        if target < nums[0]:
            return 0
        
        while start <= end:
            mid = int((start+end)/2)
            if nums[mid] > target:
                end = mid - 1
            elif nums[mid] < target:
                start = mid + 1
            else:
                return mid
        
        return end + 1