Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b0df30d

Browse filesBrowse files
authored
Merge pull request #2 from mincong-h/python
Add First-Bad-Version solution (Python 3)
2 parents a1feb5d + ee8128e commit b0df30d
Copy full SHA for b0df30d

File tree

Expand file treeCollapse file tree

1 file changed

+19
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+19
-0
lines changed
+19Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.