Skip to content

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

README.md

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

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

13+
https://leetcode.cn/problems/jian-sheng-zi-ii-lcof/
14+
15+
https://leetcode.cn/problems/jian-sheng-zi-lcof/
16+
17+
https://leetcode.cn/problems/special-positions-in-a-binary-matrix/
18+
1319
https://leetcode-cn.com/problems/maximum-length-of-pair-chain/
1420

1521
https://leetcode.cn/classic/problems/longest-univalue-path

jian-sheng-zi-ii-lcof/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function cuttingRope(n: number): number {
2+
return Number(integerBreak(BigInt(n)) % BigInt(1e9 + 7));
3+
}
4+
function integerBreak(n: bigint): bigint {
5+
if (n <= 3) return n - 1n;
6+
if (n % 3n === 0n) {
7+
return 3n ** (n / 3n);
8+
}
9+
if (n % 3n === 2n) {
10+
return 3n ** (n / 3n) * 2n;
11+
}
12+
if (n % 3n === 1n) {
13+
return 3n ** (n / 3n - 1n) * 2n * 2n;
14+
}
15+
return n;
16+
}
17+
export default cuttingRope;

jian-sheng-zi-lcof/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import integerBreak from "../integer-break/index.ts";
2+
3+
export { integerBreak as default };

maximum-length-of-pair-chain/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export default function findLongestChain(pairs: number[][]): number {
2-
32
let curr = -Infinity, res = 0;
43
pairs.sort((a, b) => a[1] - b[1]);
54
for (const p of pairs) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function numSpecial(mat: number[][]): number {
2+
const rowsum = mat.map((a) => a.reduce((q, v) => q + v, 0));
3+
const colsum = mat[0].map((_, i) => mat.reduce((q, v) => q + v[i], 0));
4+
5+
let ans = 0;
6+
7+
mat.forEach((a, i) =>
8+
a.forEach(
9+
(v, j) => (ans += Number([v, colsum[j], rowsum[i]].every((v) =>
10+
v === 1
11+
))),
12+
)
13+
);
14+
15+
return ans;
16+
}
17+
export default numSpecial;

0 commit comments

Comments
 (0)