Skip to content

Commit fa931bc

Browse files
committed
https://leetcode.cn/problems/count-servers-that-communicate/
1 parent 4691d7f commit fa931bc

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,8 @@ https://leetcode.cn/problems/find-median-from-data-stream/
888888

889889
https://leetcode.cn/problems/replace-words/
890890

891+
https://leetcode.cn/problems/count-servers-that-communicate/
892+
891893
#### 安装教程
892894

893895
1. 安装`deno`
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export default function countServers(grid: number[][]): number {
2+
const computers: Array<[number, number]> = [];
3+
4+
const count_m: Array<number> = [];
5+
const count_n: Array<number> = [];
6+
7+
grid.forEach(function (a, i) {
8+
return a.forEach((v, j) => {
9+
if (v === 1) {
10+
computers.push([i, j]);
11+
count_m[i] = 1 + (count_m[i] ?? 0);
12+
count_n[j] = 1 + (count_n[j] ?? 0);
13+
}
14+
});
15+
});
16+
17+
return computers.filter(([i, j]) => {
18+
return count_m[i] >= 2 || count_n[j] >= 2;
19+
}).length;
20+
}

0 commit comments

Comments
 (0)