Solution in Java


  • 0
    K
    class Solution {
        public int searchInsert(int[] nums, int target) {
            int pos=0;
            for(int i=0; i<nums.length; i++) {
                if (nums[i] >= target ) {
                    pos=i;
                    break;
                }
                else {
                    pos++;
                }
            }
            return pos;
        }
    }
    

Log in to reply
 

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