Skip to content

Commit 9b5ba26

Browse files
authored
Merge pull request #11 from masx200/masx200-patch-1
Masx200 patch 1
2 parents ca49221 + 8b98ab9 commit 9b5ba26

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ leetcode 测试
1010

1111
##### 包含的内容如下
1212

13+
https://leetcode-cn.com/problems/beautiful-arrangement-ii/
14+
1315
https://leetcode.cn/problems/minimum-moves-to-reach-target-with-rotations/
1416

1517
https://leetcode.cn/problems/ternary-expression-parser/

beautiful-arrangement-ii/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export default function constructArray(n: number, k: number): number[] {
2+
3+
const answer: number[] = new Array(n).fill(0);
4+
let idx = 0;
5+
for (let i = 1; i < n - k; ++i) {
6+
answer[idx] = i;
7+
++idx;
8+
}
9+
for (let i = n - k, j = n; i <= j; ++i, --j) {
10+
answer[idx] = i;
11+
++idx;
12+
if (i !== j) {
13+
answer[idx] = j;
14+
++idx;
15+
}
16+
}
17+
return answer;
18+
}

0 commit comments

Comments
 (0)