leetcode Search Insert Position

class Solution {
public:
    int searchInsert(int A[], int n, int target)
    {
        int low=0,high=n-1;
        int m=0;
        if(A[0]>target)return 0;
        while(low<=high)
        {
            m=low+(high-low)/2;
            if(A[m]==target)return m;
            if(A[m]>target)
            {
                high=m-1;
            }
            if(A[m]<target)
            {
                low=m+1;            
            }
        }
        return low;
    }
};

  

posted @ 2013-05-22 00:46  代码改变未来  阅读(171)  评论(0编辑  收藏  举报