LeetCode July Challenge - Day 1

Problem: LeetCode July Challenge - Day 1

Ideas

$$ \sum_{i=1}^k i = \frac{k\cdot (k+1)}{2}. $$

Solution:

class Solution {
    public:
        int arrangeCoins(int n) {
            return (-1 + sqrt(1+8*(long long)n))/2;
        }
};