Simple 8 line Java Solution with Iteration


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

Log in to reply
 

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