5 lines,extremely easy to understand JAVA solution


  • 0

    explanation:

    Just to count how many numbers smaller than target in nums[].

    public int searchInsert(int[] nums, int target) {
            int index = 0;
            while(nums[index] < target){
                index++;
                if(index == nums.length) break;
            }
            return index;
        }
    

Log in to reply
 

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