3 lines C++ solution


  • 0

    full staircase = (layer * (layer+1)) / 2

     int arrangeCoins(int n) {
            long layer = sqrt(2*(long)n);
            int sum = (layer * (layer+1)) / 2;
            return (sum > n) ? layer-1 : layer;
        }
    

Log in to reply
 

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