Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1472 from Ali-Al-Hadi-Al-Husseini/patch-1
Browse files Browse the repository at this point in the history
Update 153-Find-Minimum-Rotated-Sorted-Array.py
  • Loading branch information
Ahmad-A0 authored Nov 19, 2022
2 parents 3eece70 + a413fa1 commit 20ed2d3
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions python/153-Find-Minimum-in-Rotated-Sorted-Array.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
class Solution:
def findMin(self, nums: List[int]) -> int:
res = nums[0]
l, r = 0, len(nums) - 1

while l <= r:
if nums[l] < nums[r]:
res = min(res, nums[l])
break
m = (l + r) // 2
res = min(res, nums[m])
if nums[m] >= nums[l]:
l = m + 1
start , end = 0 ,len(nums) - 1
curr_min = float("inf")

while start < end :
mid = (start + end ) // 2
curr_min = min(curr_min,nums[mid])

# right has the min
if nums[mid] > nums[end]:
start = mid + 1

# left has the min
else:
r = m - 1
return res
end = mid - 1

return min(curr_min,nums[start])

0 comments on commit 20ed2d3

Please sign in to comment.