码迷,mamicode.com
首页 > 编程语言 > 详细

leetcode first bad version python

时间:2015-12-18 00:03:32      阅读:262      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!