LeetCode 35 Search Insert Position

2019-07-26 11:06:49 浏览数 (1)

题目

代码语言:javascript复制
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;
        
    }
};

0 人点赞