File tree Expand file tree Collapse file tree 3 files changed +58
-0
lines changed
solution/0900-0999/0997.Find the Town Judge Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,27 @@ class Solution:
101
101
102
102
```
103
103
104
+ ### ** TypeScript**
105
+
106
+ ``` ts
107
+ function findJudge(n : number , trust : number [][]): number {
108
+ let candidates = new Array (n ).fill (0 );
109
+ for (let [a, b] of trust ) {
110
+ candidates [a - 1 ] = - 1 ;
111
+ if (candidates [b - 1 ] >= 0 ) {
112
+ candidates [b - 1 ]++ ;
113
+ }
114
+ }
115
+
116
+ for (let i = 0 ; i < n ; i ++ ) {
117
+ if (candidates [i ] == n - 1 ) {
118
+ return i + 1 ;
119
+ }
120
+ }
121
+ return - 1 ;
122
+ };
123
+ ```
124
+
104
125
### ** ...**
105
126
106
127
```
Original file line number Diff line number Diff line change @@ -108,6 +108,27 @@ class Solution:
108
108
109
109
```
110
110
111
+ ### ** TypeScript**
112
+
113
+ ``` ts
114
+ function findJudge(n : number , trust : number [][]): number {
115
+ let candidates = new Array (n ).fill (0 );
116
+ for (let [a, b] of trust ) {
117
+ candidates [a - 1 ] = - 1 ;
118
+ if (candidates [b - 1 ] >= 0 ) {
119
+ candidates [b - 1 ]++ ;
120
+ }
121
+ }
122
+
123
+ for (let i = 0 ; i < n ; i ++ ) {
124
+ if (candidates [i ] == n - 1 ) {
125
+ return i + 1 ;
126
+ }
127
+ }
128
+ return - 1 ;
129
+ };
130
+ ```
131
+
111
132
### ** ...**
112
133
113
134
```
Original file line number Diff line number Diff line change
1
+ function findJudge ( n : number , trust : number [ ] [ ] ) : number {
2
+ let candidates = new Array ( n ) . fill ( 0 ) ;
3
+ for ( let [ a , b ] of trust ) {
4
+ candidates [ a - 1 ] = - 1 ;
5
+ if ( candidates [ b - 1 ] >= 0 ) {
6
+ candidates [ b - 1 ] ++ ;
7
+ }
8
+ }
9
+
10
+ for ( let i = 0 ; i < n ; i ++ ) {
11
+ if ( candidates [ i ] == n - 1 ) {
12
+ return i + 1 ;
13
+ }
14
+ }
15
+ return - 1 ;
16
+ } ;
You can’t perform that action at this time.
0 commit comments