mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			45 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>You are given a map of a server center, represented as a <code>m * n</code> integer matrix <code>grid</code>, 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 />
 | 
						|
<br />
 | 
						|
Return the number of servers that communicate with any other server.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Example 1:</strong></p>
 | 
						|
 | 
						|
<p><img alt="" src="https://assets.leetcode.com/uploads/2019/11/14/untitled-diagram-6.jpg" style="width: 202px; height: 203px;" /></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> grid = [[1,0],[0,1]]
 | 
						|
<strong>Output:</strong> 0
 | 
						|
<b>Explanation:</b> No servers can communicate with others.</pre>
 | 
						|
 | 
						|
<p><strong>Example 2:</strong></p>
 | 
						|
 | 
						|
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2019/11/13/untitled-diagram-4.jpg" style="width: 203px; height: 203px;" /></strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> grid = [[1,0],[1,1]]
 | 
						|
<strong>Output:</strong> 3
 | 
						|
<b>Explanation:</b> All three servers can communicate with at least one other server.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong>Example 3:</strong></p>
 | 
						|
 | 
						|
<p><img alt="" src="https://assets.leetcode.com/uploads/2019/11/14/untitled-diagram-1-3.jpg" style="width: 443px; height: 443px;" /></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> grid = [[1,1,0,0],[0,0,1,0],[0,0,1,0],[0,0,0,1]]
 | 
						|
<strong>Output:</strong> 4
 | 
						|
<b>Explanation:</b> 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.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>m == grid.length</code></li>
 | 
						|
	<li><code>n == grid[i].length</code></li>
 | 
						|
	<li><code>1 <= m <= 250</code></li>
 | 
						|
	<li><code>1 <= n <= 250</code></li>
 | 
						|
	<li><code>grid[i][j] == 0 or 1</code></li>
 | 
						|
</ul>
 |