Simple Binary Search Solution


  • 0
    A

    int searchUtil(vector<int>& nums, int target,int low,int high){
    if(target <= nums[low])
    return low;
    if(target>nums[high])
    return high+1;
    int mid=(low+high)/2;
    if(target>nums[mid])
    return searchUtil(nums,target,mid+1,high);
    return searchUtil(nums,target,low,mid-1);
    }


Log in to reply
 

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