My 0ms accepted Java solution


  • 0
    Y
    public class Solution {
    public int searchInsert(int[] nums, int target) {
        int n = 0;
        if(nums[0]>target){
            return 0;
        }
        if(nums[nums.length-1]<target){
            return nums.length;
        }
        for(int i=0; i<nums.length; i++){
            if (nums[i]==target){
                return i;
            }
            if(nums[i]<target && nums[i+1]>target){
                return i+1;
            }
        }
        return n;
    }
    

    }


Log in to reply
 

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