Skip to content

Commit 2f39b90

Browse files
committed
Added search in a rotated sorted array
1 parent 2319de6 commit 2f39b90

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

searches/search_in_a_rotated_sorted_array.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ def search_in_rotated_sorted_array(nums: list[int], target: int) -> int:
4242
if nums[middle_index] == target:
4343
return middle_index
4444

45-
# Check if left half is sorted
45+
# Check if left half is sorted array
4646
if nums[left_index] <= nums[middle_index]:
4747
# Target is in the sorted left half
4848
if nums[left_index] <= target < nums[middle_index]:
4949
right_index = middle_index - 1
50+
#If target is not in sorted part searching in other part
5051
else:
5152
left_index = middle_index + 1
5253
# Right half is sorted

0 commit comments

Comments
 (0)