Python Solution


  • 0
    R
    import math
    
    class Solution:
        def arrangeCoins(self, n):
            """
            :type n: int
            :rtype: int
            """
            return int((math.sqrt(1 + 8*n) - 1)/2)
    

    If there are x rows formed properly, we will have following equation getting satisfied
    x(x+1) / 2 < n
    Solving the quadratic equation, x^2 + x - 2n < 0, we get,
    x = { -1 + sqrt(1 + 8n) } / 2.


Log in to reply
 

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