C++/beats 27/search-insert-position


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

Log in to reply
 

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