LeetCode 35 Search Insert Position

题目

class Solution {
public:
    int searchInsert(vector<int>& nums, int target) {
        
        int start = 0;
        int end=nums.size()-1;
        
        while(start<=end)
        {
            int mid = (start+end)/2;
            
            if(target<=nums[mid])
            {
                end =mid-1;
            }
            else if(target > nums[mid])
            {
                start=mid+1;
            }
        }
        
        return start;
        
    }
};
posted @ 2019-07-25 11:46  Shendu.CC  阅读(65)  评论(0编辑  收藏  举报