Skip to content

Instantly share code, notes, and snippets.

@KeshariPiyush24
Created September 21, 2024 05:39
Show Gist options
  • Save KeshariPiyush24/3884bf09cb1a45f833c69fcf2cedabc4 to your computer and use it in GitHub Desktop.
Save KeshariPiyush24/3884bf09cb1a45f833c69fcf2cedabc4 to your computer and use it in GitHub Desktop.
153. Find Minimum in Rotated Sorted Array

Question: 153. Find Minimum in Rotated Sorted Array

Intution:

Time Complexity: $$O(log(n))$$

Space Complexity: $$O(1)$$

Solution:

class Solution {
    public int findMin(int[] nums) {
       int low = 0;
       int high = nums.length - 1;
       while(low < high) {
        int mid = low + (high - low) / 2;
        if (nums[mid] > nums[high]) low = mid + 1;
        else if (nums[low] < nums[mid]) high = mid - 1;
        else high = mid;
       }
       return nums[high];
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment