Created
May 2, 2020 05:14
-
-
Save munguial/7d8aecceed11b539732482b84ddfe100 to your computer and use it in GitHub Desktop.
Day 1 - First Bad Version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://leetcode.com/explore/challenge/card/may-leetcoding-challenge/534/week-1-may-1st-may-7th/3316/ | |
# The isBadVersion API is already defined for you. | |
# @param version, an integer | |
# @return a bool | |
# def isBadVersion(version): | |
class Solution: | |
def firstBadVersion(self, n): | |
return self.bs(1, n) | |
def bs(self, a, b): | |
if a > b: | |
return b if isBadVersion(b) else a | |
m = int((a + b) / 2) | |
if isBadVersion(m): | |
return self.bs(a, m - 1) | |
else: | |
return self.bs(m + 1, b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment