# Leetcode||35. Search Insert Position

Given a sorted array 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.

You may assume no duplicates in the array.

Here are few examples.
[1,3,5,6], 5 → 2
[1,3,5,6], 2 → 1
[1,3,5,6], 7 → 4
[1,3,5,6], 0 → 0

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

#### LeetCode35——Search Insert Position

2015-10-15 22:01:06

#### (Java)LeetCode-35. Search Insert Position

2016-08-07 21:46:08

#### Python - Search Insert Position

2016-01-16 19:52:32

#### [LeetCode]35.Search Insert Position

2015-01-24 15:07:12

#### Search Insert Position -- LeetCode

2014-03-02 07:40:19

#### LeetCode 35 Search Insert Position (C,C++,Java,Python)

2015-05-18 20:33:01

#### 【LeetCode-面试算法经典-Java实现】【035-Search Insert Position（搜索插入位置）】

2015-07-27 07:18:33

#### LeetCode35. Search Insert Position轻松解决

2016-02-21 21:14:12

#### LeetCode解题报告--Search Insert Position

2015-12-04 16:58:11

#### LeetCode Search Insert Position查找插入位置

2013-12-04 08:48:00