[LeetCode]Arranging Coins 二分Python

class Solution(object):
    def arrangeCoins(self, n):
        """
        :type n: int
        :rtype: int
        """
        l=0
        h=n
        while l<=h:
            mid = (l+h)/2;
            if (1+mid)*mid/2 <=n:
                l = mid+1
            else:
                h = mid-1
        return l-1

猜你喜欢

转载自blog.csdn.net/Csdn_jey/article/details/88861979