My 9ms c++ code


  • 0
    F
    class Solution {
    public:
        int searchInsert(vector<int>& nums, int target) {
            int left = 0, right = nums.size();
        	int mid;
        	while(left < right)
        	{
        		mid = (left + right)/2;
        		if(target > nums[mid])
        		   left = mid + 1;
        		else
        		   right = mid;
        	}
        	return left;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.