Simple Java solution


  • 0
    L
    public int firstBadVersion(int n) {
            int s = 1;
            int e = n;
            while(s<e) {
                int mid = (e-s)/2 + s;
                if(isBadVersion(mid)) {
                    e = mid;
                }
                else {
                    s = mid+1;
                }
            }
            return s;
            
        }
    

Log in to reply
 

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