def firstBadVersion(self, n):

```
if n == 1:
return 1
#calculate the midpoint
left = 0
right = n
mid = (right + left) // 2
while left < right:
if isBadVersion(mid) == True:
right = mid
mid = (right + left) // 2
elif isBadVersion(mid) == False:
left = mid
mid = (right + left) // 2
if left == right - 1:
return right
return right
```