Skip to content

Commit 1e05a21

Browse files
authored
Create 932-beautiful-array.js
1 parent cead5ef commit 1e05a21

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

932-beautiful-array.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {number} N
3+
* @return {number[]}
4+
*/
5+
const beautifulArray = function(N) {
6+
let res = [];
7+
res.push(1);
8+
while (res.length < N) {
9+
const tmp = [];
10+
for (let i of res) if (i * 2 - 1 <= N) tmp.push(i * 2 - 1);
11+
for (let i of res) if (i * 2 <= N) tmp.push(i * 2);
12+
res = tmp;
13+
}
14+
return res;
15+
};

0 commit comments

Comments
 (0)