Skip to content

Commit ee8128e

Browse files
committed
Add First-Bad-Version (Python 3)
1 parent 55723b7 commit ee8128e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# The isBadVersion API is already defined for you.
2+
# @param version, an integer
3+
# @return a bool
4+
# def isBadVersion(version):
5+
6+
class Solution:
7+
def firstBadVersion(self, n):
8+
"""
9+
:type n: int
10+
:rtype: int
11+
"""
12+
left, right = 1, n
13+
while left < right:
14+
mid = left + (right - left) // 2
15+
if isBadVersion(mid):
16+
right = mid
17+
else:
18+
left = mid + 1
19+
return left

0 commit comments

Comments
 (0)