1 parent 9739cc2 commit aece3b9Copy full SHA for aece3b9
1 file changed
LeetCode/firstBadVersion.py
@@ -0,0 +1,22 @@
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(object):
7
+ def firstBadVersion(self, n):
8
+ """
9
+ :type n: int
10
+ :rtype: int
11
12
+ l = 1
13
+ r = n
14
+ while l < r:
15
+ mid = (l+r)//2
16
+ # print(isBadVersion(mid))
17
+ if not isBadVersion(mid):
18
+ l = mid + 1
19
+ else:
20
+ r = mid
21
+ return l
22
0 commit comments