Java O(1) solution


  • 0
    D
    public class Solution {
        public int arrangeCoins(int n) {
            return arrangeCoins((long)n);
        }
    
        public int arrangeCoins(long n) {
            return (int)Math.floor((-1 + Math.sqrt(1 + 8 * n)) / 2);
        }
    }
    

Log in to reply
 

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