My java math solution (48ms)


  • 0

    public int arrangeCoins(int n) {

         long ret = (long)Math.sqrt(2* (long)n +1/4) - 1/2;
         if(n >= (ret * (ret +1)/2) && n <=((ret +1) * (ret +2)/2))              {
                return (int) ret ;
         }
         return (int) ret-1;
    

    }


Log in to reply
 

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