Java
public class Solution {
public int arrangeCoins(int n) {
int result=0;
int count=1;
while(n>0)
{
if(n-count>=0)
result++;
n=n-count;
count++;
}
return result;
}
}
Java
public class Solution {
public int arrangeCoins(int n) {
return (int)((-1 + Math.sqrt(1 + 8 * (long)n)) / 2);
}
}
网友评论