Skip to content

Commit 40e2be7

Browse files
committed
Day 3 , search insert position
Solved using while loop and there is one more option of recursion.
1 parent 0a3c450 commit 40e2be7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

day_3_search_insert_position.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def searchInsert(self, nums: List[int], target: int) -> int:
3+
start = 0
4+
end = len(nums) - 1
5+
while(start <= end):
6+
mid = start + (end-start)//2
7+
if(nums[mid] == target):
8+
return mid
9+
elif(nums[mid] < target):
10+
start = mid + 1
11+
else:
12+
end = mid - 1
13+
return start

0 commit comments

Comments
 (0)