8000 First-Bad-Versoin cpp solution · invince/Leetcode@89ef2ae · GitHub
[go: up one dir, main page]

Skip to content

Commit 89ef2ae

Browse files
committed
First-Bad-Versoin cpp solution
1 parent df4da2a commit 89ef2ae

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// The API isBadVersion is defined for you.
2+
// bool isBadVersion(int version);
3+
4+
class Solution {
5+
public:
6+
int firstBadVersion(int n) {
7+
int left = 1, right = n;
8+
while (left < right){
9+
int mid = (right - left) / 2 + left;
10+
if (isBadVersion(mid))
11+
right = mid;
12+
else left = mid + 1;
13+
}
14+
return left;
15+
}
16+
};
17+

0 commit comments

Comments
 (0)
0