2 lines C++ O(logn)


  • 0
    L
    class Solution {
    public:
        vector<int> searchRange(vector<int>& nums, int target) {
            if (!binary_search(nums.begin(), nums.end(), target)) return vector<int> {-1, -1};
            return vector<int> {lower_bound(nums.begin(), nums.end(), target) - nums.begin(), upper_bound(nums.begin(), nums.end(), target) - nums.begin() - 1};
        }
    };
    

Log in to reply
 

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