6ms Solution for Java


  • 0
    C

    Here is my short but accepted code for this question:

        class Solution {
        public int searchInsert(int[] nums, int target) {
           int idx = 0;
           for (int i : nums) {
              if (target <= i) return idx;
              else idx++;
           }
        
        return idx;
        }
    }

Log in to reply
 

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