【算法】生产手机数目

前言

Answer

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function solution(n) {
let arr = [];
let num = 1;
let flag = 1;
let sum = 0;
for (let i = 0; i < n; i++) {
if (num) {
arr.push(flag);
num--;
} else {
num = ++flag;
arr.push(num);
num--;
}
}
for (value of arr) {
sum += value;
}
return sum;
}
console.log(solution(11));