C++ simple solution using STL


  • 0
    R
        class Solution {
        public:
        vector<int> searchRange(vector<int>& A, int target) {
            int low,up;
            low=lower_bound(A.begin(),A.end(),target)-A.begin();
            up=upper_bound(A.begin(),A.end(),target)-A.begin();
            vector<int> ans;
            if(low==up)
            {
                ans.push_back(-1);
                ans.push_back(-1);
            }
            else {
                ans.push_back(low);
                ans.push_back(up-1);
            }
            return ans;
        }
    };

Log in to reply
 

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