首页 > 编程语言 > 详细

leetcode first bad version python

时间:2015-12-18 00:00:33      阅读:364      评论:0      收藏:0      [点我收藏+]
# The isBadVersion API is already defined for you.
# @param version, an integer
# @return a bool
# def isBadVersion(version):

class Solution(object):
    def firstBadVersion(self, n):
        """
        :type n: int
        :rtype: int
        """
        if n < 1:
            return -1
        left=1
        right=n
        while left + 1 < right:
            mid=(left+right)/2
            bolBad = isBadVersion(mid)
            if bolBad:
                right=mid
            else:
                left=mid
        if isBadVersion(left):
            return left
        elif isBadVersion(right):
            return right
        return -1

 

leetcode first bad version python

原文:http://www.cnblogs.com/allenhaozi/p/5055665.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!