1267. Count Servers that Communicate Medium
1/**
2 * [1267] Count Servers that Communicate
3 *
4 * You are given a map of a server center, represented as a m * n integer matrix grid, where 1 means that on that cell there is a server and 0 means that it is no server. Two servers are said to communicate if they are on the same row or on the same column.<br />
5 * <br />
6 * Return the number of servers that communicate with any other server.
7 *
8 * Example 1:
9 * <img alt="" src="https://assets.leetcode.com/uploads/2019/11/14/untitled-diagram-6.jpg" style="width: 202px; height: 203px;" />
10 *
11 * Input: grid = [[1,0],[0,1]]
12 * Output: 0
13 * Explanation: No servers can communicate with others.
14 * Example 2:
15 * <img alt="" src="https://assets.leetcode.com/uploads/2019/11/13/untitled-diagram-4.jpg" style="width: 203px; height: 203px;" />
16 *
17 * Input: grid = [[1,0],[1,1]]
18 * Output: 3
19 * Explanation: All three servers can communicate with at least one other server.
20 *
21 * Example 3:
22 * <img alt="" src="https://assets.leetcode.com/uploads/2019/11/14/untitled-diagram-1-3.jpg" style="width: 443px; height: 443px;" />
23 *
24 * Input: grid = [[1,1,0,0],[0,0,1,0],[0,0,1,0],[0,0,0,1]]
25 * Output: 4
26 * Explanation: The two servers in the first row can communicate with each other. The two servers in the third column can communicate with each other. The server at right bottom corner can't communicate with any other server.
27 *
28 *
29 * Constraints:
30 *
31 * m == grid.length
32 * n == grid[i].length
33 * 1 <= m <= 250
34 * 1 <= n <= 250
35 * grid[i][j] == 0 or 1
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/count-servers-that-communicate/
41// discuss: https://leetcode.com/problems/count-servers-that-communicate/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn count_servers(grid: Vec<Vec<i32>>) -> i32 {
47 0
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_1267() {
59 }
60}
61
Back
© 2025 bowen.ge All Rights Reserved.