DEV Community 👩‍💻👨‍💻

ZeeshanAli-0704
ZeeshanAli-0704

Posted on

Find Minimum in Rotated Sorted Array II

Find Minimum in Rotated Sorted Array II

/**
 * @param {number[]} nums
 * @return {number}
 */
var findMin = function (nums) {
  var left = 0,
    right = nums.length - 1;

  while (left < right) {
    var mid = Math.floor((left + right) / 2);
    if (nums[mid] > nums[right]) {
      left = mid + 1;
    } else if (nums[mid] === nums[right]) {
      right--;
    } else {
      right = mid;
    }
  }
  return nums[left];
};


Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Make Your Github Profile Stand Out

>> Check out this classic DEV post <<