Skip to content

Instantly share code, notes, and snippets.

@PeculiarE
Last active March 9, 2026 23:51
Show Gist options
  • Select an option

  • Save PeculiarE/d954755b5496ff0c2f29b00ff3210a83 to your computer and use it in GitHub Desktop.

Select an option

Save PeculiarE/d954755b5496ff0c2f29b00ff3210a83 to your computer and use it in GitHub Desktop.
Find Minimum in Rotated Sorted Array - LeetCode - Day 68

Question

Intuition

Approach

Complexity

  • Time complexity: $$O(log\ n)$$

  • Space complexity: $$O(1)$$

Code

class Solution:
    def findMin(self, nums: List[int]) -> int:
        low, high = 0, len(nums) - 1
        while low < high:
            mid = (low + high) // 2
            if nums[mid] > nums[high]:
                low = mid + 1
            else:
                high = mid
        return nums[low]

Result

Screenshot 2026-03-09 at 23 14 12

Intuition

A seemingly more complicated approach that I actually seem to understand better

Approach

Complexity

  • Time complexity: $$O(log\ n)$$

  • Space complexity: $$O(1)$$

Code

class Solution:
    def findMin(self, nums: List[int]) -> int:
        if len(nums) == 1:
            return nums[0]
        low, high = 0, len(nums) - 1
        while low <= high:
            mid = (low + high) // 2
            if (mid > 0 and nums[mid] < nums[mid - 1]) or (mid == 0 and nums[mid] < nums[high]):
                return nums[mid]
            elif nums[mid] > nums[high]:
                low = mid + 1
            else:
                high = mid

Result

Screenshot 2026-03-09 at 23 48 56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment