<p>Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.</p>

<p>You must&nbsp;write an algorithm with&nbsp;<code>O(log n)</code> runtime complexity.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,3,5,6], target = 5
<strong>Output:</strong> 2
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,3,5,6], target = 2
<strong>Output:</strong> 1
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,3,5,6], target = 7
<strong>Output:</strong> 4
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>4</sup></code></li>
	<li><code>-10<sup>4</sup> &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
	<li><code>nums</code> contains <strong>distinct</strong> values sorted in <strong>ascending</strong> order.</li>
	<li><code>-10<sup>4</sup> &lt;= target &lt;= 10<sup>4</sup></code></li>
</ul>

class Solution:
    def searchInsert(self, nums: List[int], target: int) -> int:
        #[1,3,5,6]
        #2
        #0:3
        #0:1
        
        #
        if target <= nums[0]:
            return 0 
        elif target > nums[-1]:
            return len(nums)
        
        
        low = 0
        high = len(nums) -1
        
        while high - low > 1:
            mid = ((high-low)//2) + low
            #print(mid, nums[mid])
            if target == nums[mid]:
                return mid
            
            if target == nums[high]:
                return high
            
            if target == nums[low]:
                return low
            
            if target < nums[mid]:
                high = mid
            else:
                low = mid 
                
            
                        
            
            
        
        return high
        
        #handle the insertion case in the event we don't find it
            
        
17200