python AC binary search solution


  • 0
    H
    class Solution(object):
        def arrangeCoins(self, n):
            """
            :type n: int
            :rtype: int
            """
            if not n:
                return 0
            
            i, j = 1, n
            while i + 1 < j:
                mid = (i + j) // 2
                if ((1 + mid) * mid) // 2 <= n:
                    i = mid
                else:
                    j = mid
                    
            return j if ((1 + j) * j) // 2 <= n else i
    

Log in to reply
 

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