Skip to content

Commit 5d587ef

Browse files
author
cpppy
authored
Create 278_First_Bad_Version.cc
1 parent ba447f4 commit 5d587ef

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

278_First_Bad_Version.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Forward declaration of isBadVersion API.
2+
bool isBadVersion(int version);
3+
4+
class Solution {
5+
public:
6+
int firstBadVersion(int n) {
7+
int low=1;
8+
int high=n;
9+
int ver=0;
10+
while(low<high){
11+
ver=low+(high-low)/2;
12+
if(isBadVersion(ver)){
13+
high=ver;
14+
}
15+
else{
16+
low=ver+1;
17+
}
18+
}
19+
return low;
20+
21+
22+
23+
}
24+
};

0 commit comments

Comments
 (0)