(int[][] grid)
| 1 | class Solution { |
| 2 | public int countServers(int[][] grid) { |
| 3 | int n = grid.length; |
| 4 | int m = grid[0].length; |
| 5 | int rowCount[] = new int[n]; |
| 6 | int colCount[] = new int[m]; |
| 7 | int count=0; |
| 8 | for(int i=0;i<n;i++){ |
| 9 | for(int j=0;j<m;j++){ |
| 10 | if(grid[i][j] == 1){ |
| 11 | rowCount[i]++; |
| 12 | colCount[j]++; |
| 13 | count++; |
| 14 | } |
| 15 | } |
| 16 | } |
| 17 | for(int i=0;i<n;i++){ |
| 18 | for(int j=0;j<m;j++){ |
| 19 | if(grid[i][j] == 1){ |
| 20 | // remove unreachable servers |
| 21 | if(rowCount[i] == 1 && colCount[j]==1) |
| 22 | count--; |
| 23 | } |
| 24 | } |
| 25 | } |
| 26 | return count; |
| 27 | } |
| 28 | } |
nothing calls this directly
no outgoing calls
no test coverage detected