码迷,mamicode.com
首页 > 其他好文 > 详细

Search Insert Position

时间:2015-03-29 20:54:30      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:

/*
简单二分
*/
class Solution {
public:
    int searchInsert(int A[], int n, int target) {
        int l = 0,r = n-1,mid ;
        while(l<=r){
            mid = l+(r-l)/2;
            if(A[mid] == target) return mid;
            else if(A[mid]>target) r = mid-1;
            else l = mid+1;
        }
        return l;
    }
};

 

Search Insert Position

标签:

原文地址:http://www.cnblogs.com/llei1573/p/4376260.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!