题解 | 二分查找-I

二分查找-I

https://www.nowcoder.com/practice/d3df40bd23594118b57554129cadf47b

#include <stdio.h>

int search(int* nums, int numsLen, int target ) {
    // write code here
    int low = 0, hight = numsLen-1;
    while(low<=hight){
        int mid = (low+hight)/2;
        if(nums[mid] == target){
            return mid;
        }else if(nums[mid] < target){
            low++;
        }else {
            hight--;
        }
    }
    return -1;
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务