Solution in Java


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

  • 0
    A
    This post is deleted!

Log in to reply
 

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