LC 35. Search Insert Position

Nilanjan Deb · April 5, 2020

This is my CPP solution.

class Solution {
public:
    int searchInsert(vector<int>& nums, int target) {
        int n = nums.size();
        for(int i=0;i<n;i++){
            if(nums[i] ==  target){
                return i;
            }
        }
        for(int i=0;i<n;i++){
            if(nums[i]>target){
                return i;
            }
        }
        return n;
    }
};


Dicussion Forum