We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1adaddd commit 1882fbbCopy full SHA for 1882fbb
scripts/algorithms/C/Count Servers that Communicate/Count Servers that Communicate.rs
@@ -0,0 +1,32 @@
1
+// Runtime: 0 ms (Top 100.0%) | Memory: 2.60 MB (Top 50.0%)
2
+
3
+impl Solution {
4
+ pub fn count_servers(grid: Vec<Vec<i32>>) -> i32 {
5
+ let n :usize= grid.len();
6
+ let m :usize = grid[0].len();
7
+ let mut row: Vec<i32> = vec![0;n];
8
+ let mut col: Vec<i32> = vec![0;m];
9
10
+ let mut res: i32 = 0;
11
12
+ //count number of servers in each row and column
13
+ for i in 0..n{
14
+ for j in 0..m{
15
+ if grid[i][j]==1{
16
+ row[i]+=1;
17
+ col[j]+=1;
18
+ }
19
20
21
22
+ //count number of servers not alone in either row or column
23
24
25
+ if grid[i][j]==1 && (row[i]>1||col[j]>1){
26
+ res+=1;
27
28
29
30
+ return res;
31
32
+}
0 commit comments