Time Limit Exceeded for my code


  • 0
    Z

    Hi guys, My code has a time limit exceeded problem, can any one help me with it?
    class Solution {
    public:
    int searchInsert(vector<int>& nums, int target) {
    int start =0;
    int end = nums.size()-1;

        while(start<=end){
            
            int mid = start +(end-start)/2;
            
            if(nums[mid]<target)
            start=mid+1;
            else if(nums[mid]>target)
            end=mid-1;
        }
        return start;
    }
    

    };


Log in to reply
 

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