deno.land / x / masx200_leetcode_test@10.6.5 / count-servers-that-communicate / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
export default function countServers(grid: number[][]): number { const computers: Array<[number, number]> = [];
const count_m: Array<number> = []; const count_n: Array<number> = [];
grid.forEach(function (a, i) { return a.forEach((v, j) => { if (v === 1) { computers.push([i, j]); count_m[i] = 1 + (count_m[i] ?? 0); count_n[j] = 1 + (count_n[j] ?? 0); } }); });
return computers.filter(([i, j]) => { return count_m[i] >= 2 || count_n[j] >= 2; }).length;}
masx200_leetcode_test

Version Info

Tagged at
a year ago