<1ms Simple Java solution (6 lines)


  • 0
    A

    Hello all,

    here is my simple solution.

    public class Solution {
        public int searchInsert(int[] nums, int target) {
            if (nums.length == 0)
                return 0;
            int i = 0;
            while (i < nums.length && nums[i] < target)
                i++;
            return i;
        }
    }

Log in to reply
 

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