Java Solution strictly according to clrs with O(logn) complexity


  • 0
    D
        public int searchInsert(int[] nums, int target) {
            int r = nums.length;
    		int l = 0; 
    		while(l < r){
    			int mid = (l+r)/2;
    			if(nums[mid] < target)
    				l = mid +1;
    			else
    				r = mid;
    		}
    		return l;
            }
        }
    

Log in to reply
 

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