My JAVA Solution


  • 1
    Q
        public int firstBadVersion(int n) {
            int low = 1;
            int high = n;
            int mid = low + (high - low)/2;
            
            while(low < high){
                if(!isBadVersion(mid)){
                    low = mid + 1;
                    mid = low + (high - low)/2;
                }
                else{
                    high = mid;
                    mid = low + (high - low)/2;
                }
            }
            
            return mid;
        }
    

Log in to reply
 

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