Skip to content

Commit 4f67240

Browse files
Added solution1 for 30-days-of-leetcode
1 parent 6037fde commit 4f67240

File tree

1 file changed

+22
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)