Skip to content

Commit 5ea9e1c

Browse files
authored
Create 278. First Bad Version.java
1 parent 62b5170 commit 5ea9e1c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

278. First Bad Version.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 low = 1, high = n;
7+
while(low < high) {
8+
int mid = low + (high-low)/2;
9+
boolean answer = isBadVersion(mid);
10+
if(answer==false) {
11+
low = mid+1;
12+
}
13+
else {
14+
high = mid;
15+
}
16+
}
17+
return low;
18+
}
19+
}

0 commit comments

Comments
 (0)