Why TLE?


  • 0
    Y

    In the 12th line of the following code, if I use start = mid, it will be AC; but if I use start = mid+1, it will TLE. Why?

    public class Solution extends VersionControl {
        public int firstBadVersion(int n) {
            int start = 1;
            int end = n;
            while(start + 1 < end){
                int mid = start + (end - start) / 2;
                boolean flag = isBadVersion(mid);
                if(flag){
                    end = mid;
                } 
                else{
                    start = mid + 1;
                    //start = mid;
                }
            }
            if(isBadVersion(start)){
                return start;
            }
            return end;
        }
    }
    

Log in to reply
 

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