My C# solution, simple few lines of code, O(n)


  • 0
    B
    public int SearchInsert(int[] nums, int target) {
            for(int i = 0; i < nums.Length; i++) {
                if(nums[i] == target || target < nums[i]) { return i; }
            }
            
            return nums.Length;
        }
    

Log in to reply
 

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