Skip to content

Commit 2efc133

Browse files
committed
https://leetcode.cn/problems/ccw6C7/
1 parent 3ead9e6 commit 2efc133

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Step 2. Add the dependency
4545

4646
<summary>展开查看</summary>
4747

48+
https://leetcode.cn/problems/ccw6C7/
49+
4850
https://leetcode.cn/problems/WhsWhI/
4951

5052
https://leetcode.cn/problems/longest-consecutive-sequence/

WhsWhI/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import longestConsecutive from "../longest-consecutive-sequence/index.ts";
2-
3-
export default longestConsecutive;
1+
import longestConsecutive from "../longest-consecutive-sequence/index.ts";
2+
3+
export default longestConsecutive;

ccw6C7/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export default function paintingPlan(n: number, k: number): number {
2+
if (k === n * n) return 1;
3+
4+
let res = 0;
5+
for (let a = 0; a <= n; a++) {
6+
for (let b = 0; b <= n; b++) {
7+
if (a * n + b * (n - a) === k) {
8+
res += combination(a, n) * combination(b, n);
9+
}
10+
}
11+
}
12+
return res;
13+
}
14+
export function combination(m: number, n: number): number {
15+
if (m === 0) return 1;
16+
let num1 = 1;
17+
let num2 = 1;
18+
let num3 = 1;
19+
for (let i = n; i > 0; i--) num1 *= i;
20+
for (let i = m; i > 0; i--) num2 *= i;
21+
for (let i = n - m; i > 0; i--) num3 *= i;
22+
return num1 / (num2 * num3);
23+
}

0 commit comments

Comments
 (0)