Cpp bisection search 4ms


  • 0
    P
    class Solution {
    public:
        int findMin(vector<int>& nums) {
            int left = 0, right = nums.size()-1;
            if(nums[left]<nums[right]) return nums[left];
            while(right>left+1){
                int c = (left+right)/2;
                if(nums[c]>nums[left]) left = c;
                else right = c;
            }
            return nums[right];
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.