Skip to content
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
CodexploreRepo
leetcode
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
leetcode
/
solution
/
278_First_Bad_Version.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
25 lines (21 loc) · 548 Bytes
master
Breadcrumbs
leetcode
/
solution
/
278_First_Bad_Version.py
Copy path
Top
File metadata and controls
Code
Blame
25 lines (21 loc) · 548 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# The isBadVersion API is already defined for you.
# @param version, an integer
# @return a bool
# def isBadVersion(version):
class Solution(object):
def firstBadVersion(self, n):
"""
:type n: int
:rtype: int
1 2 3 4
left, right = 1, 4
mid = 2
"""
left, right = 1, n
while left <= right:
mid = left + (right - left) // 2
if isBadVersion(mid):
right = mid - 1
else:
left = mid + 1
return left
You can’t perform that action at this time.