Skip to content

Latest commit

 

History

History
29 lines (25 loc) · 699 Bytes

Question_153.md

File metadata and controls

29 lines (25 loc) · 699 Bytes

LeetCode Records - Question 153 Find Minimum in Rotated Sorted Array

Attempt 1: Use binary search

class Solution {
    public int findMin(int[] nums) {
        int low = 0;
        int high = nums.length - 1;

        while (true) {
            int middle = (low + high) / 2;
            
            if (nums[low] <= nums[middle]) {
                if (nums[middle] <= nums[high]) {
                    return nums[low];
                } else {
                    low = middle + 1;
                }
            } else {
                high = middle;
            }
        }
    }
}
  • Runtime: 0 ms (Beats: 100.00%)
  • Memory: 42.08 MB (Beats: 32.25%)