8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 55723b7 + 35b791e commit a1feb5dCopy full SHA for a1feb5d
May-LeetCoding-Challenge/First-Bad-Version/First-Bad-Version.java
@@ -0,0 +1,18 @@
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 start = 1, end = n;
7
+ int mid = start + (end - start) / 2;
8
+ while (start < end) {
9
+ if (isBadVersion(mid)) {
10
+ end = mid;
11
+ } else {
12
+ start = mid + 1;
13
+ }
14
+ mid = start + (end - start) / 2;
15
16
+ return mid;
17
18
+}
0 commit comments