src/main/java/com/leetcode/binarysearch/medium/FindMinimumInRotatedSortedArray_153.java
public int findMin(int[] nums) {
      int left = 0;
      int right = nums.length - 1;
      int ans = -1;

      int leftMin = nums[0];

      while (left <= right) {
        int mid = left + (right - left) / 2;

        if (nums[mid] < leftMin) {
          right = mid - 1;
          ans = mid;
        } else {
          left = mid + 1;
        }
      }
      return ans == -1 ? nums[0] : nums[ans];
    }
/*
      O(log(n) Runtime: 0 ms, faster than 100.00% of Java online submissions for Find Minimum in Rotated Sorted Array.
      O(1)  Memory Usage: 39.8 MB, less than 8.97% of Java online submissions for Find Minimum in Rotated Sorted Array.
    */
O(log(n) Runtime: 0 ms, faster than 100.00% of Java online submissions for Find Minimum in Rotated Sorted Array.
O(1)  Memory Usage: 39.8 MB, less than 8.97% of Java online submissions for Find Minimum in Rotated Sorted Array.
O ( log ( n ) Runtime : 0 ms faster than 100 . 00% of Java online submissions for Find Minimum in Rotated Sorted Array . O ( 1 ) Memory Usage : 39 . 8 MB less than 8 . 97% of Java online submissions for Find Minimum in Rotated Sorted Array .
public int findMin(int[] nums) {
      int left = 0;
      int right = nums.length - 1;
      int ans = -1;
      int leftMin = nums[0];
      while (left <= right) {
        int mid = left + (right - left) / 2;
        if (nums[mid] < leftMin) {
          right = mid - 1;
          ans = mid;
        } else {
          left = mid + 1;
        }
      }
      return ans == -1 ? nums[0] : nums[ans];
    }
public int findMin ( int [ ] nums ) { int left = 0 ; int right = nums . length - 1 ; int ans = - 1 ; int leftMin = nums [ 0 ] ; while ( left <= right ) { int mid = left + ( right - left ) / 2 ; if ( nums [ mid ] < leftMin ) { right = mid - 1 ; ans = mid ; } else { left = mid + 1 ; } } return ans == - 1 ? nums [ 0 ] : nums [ ans ] ; }
O(log(n) Runtime: 0 ms, faster than 100.00% of Java online submissions for Find Minimum in Rotated Sorted Array.
O ( log ( n ) Runtime : 0 ms faster than 100 . 00% of Java online submissions for Find Minimum in Rotated Sorted Array .