my straightforward java solution


  • 0
    1
    public int searchInsert(int[] nums, int target) {
    
    		int index = 0;
    
    		for (int i = 0; i < nums.length; i++) {
    
    			if (target > nums[i])
    				index = i + 1;
    			if (target == nums[i])
    				return i;
    			if (target < nums[i])
    				break;
    		}
    
    		return index;
    	}
    

Log in to reply
 

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