|
1 | 1 | packagecom.fishercoder.solutions;
|
2 | 2 |
|
3 |
| -importcom.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 |
| - * */ |
36 | 3 | publicclass_1267 {
|
37 | 4 | publicstaticclassSolution1 {
|
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 | + */ |
39 | 8 | publicintcountServers(int[][]grid) {
|
40 | 9 | intm =grid.length;
|
41 | 10 | intn =grid[0].length;
|
|