441.排列钢镚(javascript)441.ArrangingCoins
原创你总共有 n 硬币和按步骤排列的计划。对于 k 线路的阶梯,它的第一个。 i 行必须精确 i 一枚硬币。梯子的最后一行 可能 不完整。
给你一个号码 n 、计算和返回。 完整阶梯行 总行数。
You have n coins and you want to build a staircase with these coins. The staircase consists of k rows where the ith row has exactly i coins. The last row of the staircase may be incomplete.
Given the integer n, return the number of complete rows of the staircase you will build.
示例 1:
输入:n = 5
输出:2
说明:因为第三行不完整,所以返回。 2 。
示例 2:
输入:n = 8
输出:3
说明:因为第四行不完整,所以返回。 3 。
var arrangeCoins = function (n) {
let current = 0
let i = 0
let sum = n
while (sum - i > 0) {
i++
sum -= i
current++
}
return current
};
leetcode: https://leetcode-cn.com/problems/arranging-coins/
版权声明
所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除
itfan123






