Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a1feb5d

Browse filesBrowse files
authored
Merge pull request AlgoStudyGroup#1 from mincong-h/first-bad-version
Add First-Bad-Version Java solution
2 parents 55723b7 + 35b791e commit a1feb5d
Copy full SHA for a1feb5d

File tree

Expand file treeCollapse file tree

1 file changed

+18
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+18
-0
lines changed
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.