Leetcode 154 Solution

This article provides solution to leetcode question 154 (find-minimum-in-rotated-sorted-array-ii)

https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii

Solution

class Solution:
    def findMin(self, nums: List[int]) -> int:
        l = 0
        r = len(nums) - 1

        while nums[l] == nums[r] and l < r:
            l += 1

        while l < r:
            m = (l + r) // 2
            if nums[m] <= nums[-1]:
                r = m
            else:
                l = m + 1
        return nums[l]