/* The isBadVersion API is defined in the parent class VersionControl.
      boolean isBadVersion(int version); */

public class Solution extends VersionControl {
    public int firstBadVersion(int n) {
        int l = 1, r = n;
        while (l <= r) {
            int m = l + (r - l) / 2; // key point: avoid overflow which causes strange behavior of m
            if (isBadVersion(m)) {
                r = m - 1;
            } else {
                l = m + 1;
            }
        }
        
        return l;
    }
}

@@ -262,33 +262,8 @@
     
- int m = l + (r - l) / 2;
  // 
@@ -323,16 +323,54 @@
 or of m%0A
+            int m = l + (r - l) / 2; %0A
         

Update FirstBadVersion_001.java