File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -155,6 +155,28 @@ func transportationHub(path [][]int) int {
155
155
}
156
156
```
157
157
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
+
158
180
### ** ...**
159
181
160
182
```
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments