Skip to content

Commit 3d56862

Browse files
committed
feat: add solutions to lcp problem: No.62
1 parent 096da87 commit 3d56862

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

lcp/LCP 62. 交通枢纽/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,28 @@ func transportationHub(path [][]int) int {
155155
}
156156
```
157157

158+
### **TypeScript**
159+
160+
```ts
161+
function transportationHub(path: number[][]): number {
162+
const ind: number[] = new Array(1001).fill(0);
163+
const outd: number[] = new Array(1001).fill(0);
164+
const s: Set<number> = new Set();
165+
for (const [a, b] of path) {
166+
s.add(a);
167+
s.add(b);
168+
ind[b]++;
169+
outd[a]++;
170+
}
171+
for (const c of s) {
172+
if (ind[c] === s.size - 1 && outd[c] === 0) {
173+
return c;
174+
}
175+
}
176+
return -1;
177+
}
178+
```
179+
158180
### **...**
159181

160182
```

lcp/LCP 62. 交通枢纽/Solution.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function transportationHub(path: number[][]): number {
2+
const ind: number[] = new Array(1001).fill(0);
3+
const outd: number[] = new Array(1001).fill(0);
4+
const s: Set<number> = new Set();
5+
for (const [a, b] of path) {
6+
s.add(a);
7+
s.add(b);
8+
ind[b]++;
9+
outd[a]++;
10+
}
11+
for (const c of s) {
12+
if (ind[c] === s.size - 1 && outd[c] === 0) {
13+
return c;
14+
}
15+
}
16+
return -1;
17+
}

0 commit comments

Comments
 (0)