Simple Java solution


  • 0
    M
    class Solution {
        public int searchInsert(int[] nums, int target) {
            int n =0;
            while(n!=nums.length)
            {
                if(nums[n] == target)
                    return n;
                if(target > nums[n])
                    n++;
                else
                    break;
            }
            return n;
        }
    }
    

Log in to reply
 

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