LeetCode Solutions
441. Arranging Coins
Time: $O(1)$ Space: $O(1)$
class Solution {
public:
int arrangeCoins(long n) {
return (-1 + sqrt(8 * n + 1)) / 2;
}
};
class Solution {
public int arrangeCoins(long n) {
return (int) (-1 + Math.sqrt(8 * n + 1)) / 2;
}
}
class Solution:
def arrangeCoins(self, n: int) -> int:
return int((-1 + sqrt(8 * n + 1)) // 2)