C++ using low_bound


  • 0
    R
    class Solution {
    public:
        int searchInsert(vector<int>& nums, int target) {
            vector<int>::iterator low;
            
            low = lower_bound(nums.begin(), nums.end(), target);
            
            int index = low - nums.begin();
            cout << nums[index];
            
            return index;
        }
    };

Log in to reply
 

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