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.
1 parent a45d17e commit b4862ffCopy full SHA for b4862ff
Algorithms Basics/Chapter 6. Binary Search/278. First Bad Version.cs
@@ -0,0 +1,20 @@
1
+/* The isBadVersion API is defined in the parent class VersionControl.
2
+ bool IsBadVersion(int version); */
3
+
4
+public class Solution : VersionControl {
5
+ public int FirstBadVersion(int n) {
6
+ if (n == 0) return 0;
7
+ int start = 1;
8
+ int end = n;
9
+ while (start + 1 < end) {
10
+ int mid = start + (end - start) / 2;
11
+ if (IsBadVersion(mid)) {
12
+ end = mid;
13
+ } else {
14
+ start = mid;
15
+ }
16
17
+ if (IsBadVersion(start)) return start;
18
+ return end;
19
20
+}
0 commit comments