Skip to content

Commit 02728d5

Browse files
committed
1 parent de134ca commit 02728d5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

278/step5.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
bisect_left
3+
https://github.com/python/cpython/blob/main/Lib/bisect.py
4+
を参考に書いたコード
5+
*/
6+
class Solution {
7+
public:
8+
int firstBadVersion(int n) {
9+
int left = 1;
10+
int right = n;
11+
12+
while (left < right) {
13+
int mid = left + (right - left) / 2;
14+
if (isBadVersion(mid)) {
15+
right = mid;
16+
} else {
17+
left = mid + 1;
18+
}
19+
}
20+
21+
return left;
22+
}
23+
};

0 commit comments

Comments
 (0)