My c# solution


  • 0
    C

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