Skip to content

Commit de134ca

Browse files
committed
Add step4 as simple logic
1 parent ba7a592 commit de134ca

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

278/step4.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
int firstBadVersion(int n) {
4+
if (isBadVersion(1)) {
5+
return 1;
6+
}
7+
8+
int left = 1;
9+
int right = n;
10+
11+
while (left + 1 < right) {
12+
int mid = left + (right - left) / 2;
13+
if (isBadVersion(mid)) {
14+
right = mid;
15+
} else {
16+
left = mid;
17+
}
18+
}
19+
return right;
20+
}
21+
};

0 commit comments

Comments
 (0)