-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path35.py
26 lines (25 loc) · 1.04 KB
/
35.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
__________________________________________________________________________________________________
sample 28 ms submission
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
if len(nums) == 0:
return 0
if len(nums) == 1:
if target > nums[0]:
return 1
return 0
midpoint = len(nums) // 2
if target >= nums[midpoint]:
return midpoint + self.searchInsert(nums[midpoint:], target)
else:
return self.searchInsert(nums[:midpoint], target)
__________________________________________________________________________________________________
sample 13240 kb submission
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
# for i, num in enumerate(nums):
for i in range(len(nums)):
if nums[i] >= target:
return i
return len(nums)
__________________________________________________________________________________________________