Isn`t it actually a very simple problem?


  • -4
    D
    class Solution {
    public:
        vector<int> searchRange(vector<int>& nums, int target) {
            vector<int> result(2,-1);
            bool isFirst=true;
            for(int i = 0; i < nums.size(); i++) 
            {
                if(nums[i]==target && isFirst==true)
                {
                    result[0]=i;
                    result[1]=i;
                    isFirst=false;
                    continue;
                }
                if(nums[i]==target && isFirst==false)
                {
                    result[1]++;
                    continue;
                }
                if(nums[i]>target)
                break;
            }
            return result;
        }
    };

  • 0
    M

    the requirement is O(logn) solution. But yours is O(n):)


  • 0
    C

    you should have an O(log(n)) solution


Log in to reply
 

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