### 35. Search Insert Position

题目:
<https://leetcode.com/problems/search-insert-position/>


难度:

Medium

找到第一个比```target```大的值的```index```，如果没找到则返回```len(nums)```,但是代码中直接返回```i```值就行了

### 思路一：暴力

```python
class Solution(object):
    def searchInsert(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: int
        """
        i = 0
        while nums[i] < target:
            i += 1
            if i == len(nums):
                return i
        return i
```
### 思路二：二分

```python
class Solution(object):
    def searchInsert(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: int
        """
        left, right = 0, len(nums) - 1
        while left <= right:
            mid = left + ((right - left) >> 2)
            if nums[mid] < target:
                left = mid + 1
            else:
                right = mid - 1
        return left
```
