Java Solution


  • 0
    S
        public int arrangeCoins(int n) {
            if (n <= 0) {
                return 0;
            }
            int sum = 0;
            int i;
            for (i = 1; i <= n; i++) {
                sum += i;
                if (n - sum < (i + 1)) {
                    break;
                }
            }
            return i;
        }
    

Log in to reply
 

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