Skip to content

Commit 04000c5

Browse files
refactor 1267
1 parent ad21bce commit 04000c5

File tree

1 file changed

+3
-34
lines changed

1 file changed

+3
-34
lines changed

src/main/java/com/fishercoder/solutions/_1267.java

+3-34
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,10 @@
11
package com.fishercoder.solutions;
22

3-
import com.fishercoder.common.utils.CommonUtils;
4-
5-
/**
6-
* 1267. Count Servers that Communicate
7-
*
8-
* 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.
9-
* Two servers are said to communicate if they are on the same row or on the same column.
10-
*
11-
* Return the number of servers that communicate with any other server.
12-
*
13-
* Example 1:
14-
* Input: grid = [[1,0],[0,1]]
15-
* Output: 0
16-
* Explanation: No servers can communicate with others.
17-
*
18-
* Example 2:
19-
* Input: grid = [[1,0],[1,1]]
20-
* Output: 3
21-
* Explanation: All three servers can communicate with at least one other server.
22-
*
23-
* Example 3:
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.
27-
* 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.
28-
*
29-
* Constraints:
30-
* m == grid.length
31-
* n == grid[i].length
32-
* 1 <= m <= 250
33-
* 1 <= n <= 250
34-
* grid[i][j] == 0 or 1
35-
* */
363
public class _1267 {
374
public static class Solution1 {
38-
/**credit: https://leetcode.com/problems/count-servers-that-communicate/discuss/436188/Java-or-Clean-And-Simple-or-Beats-100*/
5+
/**
6+
* credit: https://leetcode.com/problems/count-servers-that-communicate/discuss/436188/Java-or-Clean-And-Simple-or-Beats-100
7+
*/
398
public int countServers(int[][] grid) {
409
int m = grid.length;
4110
int n = grid[0].length;

0 commit comments

Comments
 (0)