Two lines C++ code ,using lower_bound() in STL


  • 0
    K
    class Solution {
    public:
        int searchInsert(vector<int>& nums, int target) {
            vector<int>::iterator it = lower_bound(nums.begin(),nums.end(),target);
            return (it-nums.begin());
        }
    };
    

Log in to reply
 

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