-
Notifications
You must be signed in to change notification settings - Fork 0
/
insert.py
40 lines (33 loc) · 923 Bytes
/
insert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
__author__ = 'yuyue'
def searchInsert(nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: int
"""
start = 0
stop = len(nums) - 1
def search(nums, target, start, stop):
middle = (start + stop) / 2
if stop - start <= 1:
if nums[middle] == target:
return middle
else:
print 'a'
result = middle + 1
return start
else:
if nums[middle] < target:
search(nums, target, middle, stop)
elif nums[middle] > target:
search(nums, target, start, middle)
elif nums[middle] == target:
return middle
if target > nums[stop]:
return stop + 1
if target < nums[start]:
return start
a=search(nums, target, start, stop)
return a
a=searchInsert([1, 3, 5], 5)
print a