```
def bisearch(self, upper, n):
mid = upper / 2
if not isBadVersion(mid) and isBadVersion(mid + 1):
return mid + 1
elif not isBadVersion(mid):
return self.bisearch(mid + n, n)
else:
return self.bisearch(mid, mid)
def firstBadVersion(self, n):
return self.bisearch(n, n)
```