Skip to content

441 arranging coins

441. Arranging Coins

题目: https://leetcode.com/problems/arranging-coins/

难度: Easy

可以直接O(1),公式:

i(i+1)/2 = n

解i

i = ( sqrt(8*n+1) -1 )/ 2

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


回到顶部