DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

ZeeshanAli-0704
ZeeshanAli-0704

Posted on

Find Minimum in Rotated Sorted Array

Find Minimum in Rotated Sorted Array

/**
 * @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 right = mid
    }
    return nums[left]
};
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Hey 😍

Want to help the DEV Community feel more like a community?

Head over to the Welcome Thread and greet some new community members!

It only takes a minute of your time, and goes a long way!