Skip to content

Commit a69bd02

Browse files
committed
feat: add typescript solution to lc problem: No.0997.Find the Town Judge
1 parent b08fb30 commit a69bd02

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

solution/0900-0999/0997.Find the Town Judge/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,27 @@ class Solution:
101101

102102
```
103103

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+
104125
### **...**
105126

106127
```

solution/0900-0999/0997.Find the Town Judge/README_EN.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,27 @@ class Solution:
108108

109109
```
110110

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+
111132
### **...**
112133

113134
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
};

0 commit comments

Comments
 (0)