Simple binary search with iteration in Python


  • 2
    K
    class Solution(object):
    def firstBadVersion(self, n):
    	beg=1
    	while not beg==n:
    	   mid=(beg+n)/2
    	   if isBadVersion(mid):
    	       n=mid
    	   else:
    	       beg=mid+1
    	return beg

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.