using binary search(JAVA)


  • 0
    M
    public class Solution extends VersionControl {
        public int firstBadVersion(int n) {
            int start=1;
            int end=n;
            while(start!=end){
                int mid=start+(end-start)/2;
                if(isBadVersion(mid)){
                    end=mid;
                }else{
                    start=mid+1;
                }
            }
            return start;
        }
    }
    

Log in to reply
 

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