My 8 lines C++ solution


  • -2
    S

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


Log in to reply
 

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