【leetcode】704. 二分查找

 

int bs(int* nums,int left,int right,int target){
    if(left>right) return -1;
    int mid=(left+right)/2;
    if(nums[mid] > target){
        return bs(nums,left,mid-1,target);
    }
    else if(nums[mid] < target){
        return bs(nums,mid+1,right,target);
    }
    else{
        return mid;
    }
}
int search(int* nums, int numsSize, int target){
    return bs(nums,0,numsSize-1,target);
}

 

上一篇:leetcode 704. binary-search 二分查找 python3


下一篇:CYQ.Data V4系列全面开源(2013-08-04)