Advertisement
GokulDeep

Quality check

Jun 18th, 2024
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. /* The isBadVersion API is defined in the parent class VersionControl.
  2.       boolean isBadVersion(int version); */
  3.  
  4. public class Solution extends VersionControl {
  5.     public int firstBadVersion(int n) {
  6.         int f = 0;
  7.         int b = n-1;
  8.         int ans = 0;
  9.  
  10.         while (f <= b) {
  11.             int m = (f + b) / 2;
  12.             boolean x = isBadVersion(m+1);
  13.             if (x == true) {
  14.                 b = m-1;
  15.                 ans = m+1;
  16.                 System.out.println(ans);
  17.             } else {
  18.                 f = m+1;
  19.             }
  20.         }
  21.         return ans;
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement