File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
count-servers-that-communicate Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -888,6 +888,8 @@ https://leetcode.cn/problems/find-median-from-data-stream/
888
888
889
889
https://leetcode.cn/problems/replace-words/
890
890
891
+ https://leetcode.cn/problems/count-servers-that-communicate/
892
+
891
893
#### 安装教程
892
894
893
895
1 . 安装` deno `
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments