Skip to content

Commit 8824bb2

Browse files

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,10 @@ https://leetcode.cn/problems/cells-with-odd-values-in-a-matrix/
896896

897897
https://leetcode.cn/problems/set-intersection-size-at-least-two
898898

899+
https://leetcode.cn/problems/sequence-reconstruction/
900+
901+
https://leetcode.cn/problems/ur2n8P/
902+
899903
#### 安装教程
900904

901905
1. 安装`deno`

sequence-reconstruction/index.ts

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

ur2n8P/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function sequenceReconstruction(
2+
nums: number[],
3+
sequences: number[][],
4+
): boolean {
5+
const s = new Set<string>();
6+
for (const seq of sequences) {
7+
for (let i = 0; i < seq.length - 1; i++) {
8+
s.add(hash(seq[i], seq[i + 1]));
9+
}
10+
}
11+
for (let i = 0; i < nums.length - 1; i++) {
12+
if (!s.has(hash(nums[i], nums[i + 1]))) {
13+
return false;
14+
}
15+
}
16+
return true;
17+
}
18+
19+
function hash(arg0: number, arg1: number): string {
20+
return JSON.stringify([arg0, arg1]);
21+
}
22+
export default sequenceReconstruction;

0 commit comments

Comments
 (0)