-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path278.py
39 lines (29 loc) · 775 Bytes
/
278.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = ['"wuyadong" <[email protected]>']
# The isBadVersion API is already defined for you.
# @param version, an integer
# @return a bool
# def isBadVersion(version):
def isBadVersion(v):
return False
class Solution(object):
def firstBadVersion(self, n):
"""
:type n: int
:rtype: int
"""
start = 1
end = n
while start < end:
if start+1 == end:
if isBadVersion(start):
return start
else:
return end
mid = (start+end)/2
if isBadVersion(mid):
end = mid
else:
start = mid
return start