Solution in C#


  • 0
    R

    Just go through the array and find the target or first element that above the target and return it`s index.

    public class Solution {
        public int SearchInsert(int[] nums, int target) {
            for(int i = 0; i < nums.Length; i++)
                {
                    if(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.