mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
54 lines
1.9 KiB
HTML
54 lines
1.9 KiB
HTML
<p>给你一个大小为 <code>rows x cols</code> 的矩阵 <code>mat</code>,其中 <code>mat[i][j]</code> 是 <code>0</code> 或 <code>1</code>,请返回 <strong>矩阵 <em><code>mat</code></em> 中特殊位置的数目</strong> 。</p>
|
||
|
||
<p><strong>特殊位置</strong> 定义:如果 <code>mat[i][j] == 1</code> 并且第 <code>i</code> 行和第 <code>j</code> 列中的所有其他元素均为 <code>0</code>(行和列的下标均 <strong>从 0 开始</strong> ),则位置 <code>(i, j)</code> 被称为特殊位置。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<pre><strong>输入:</strong>mat = [[1,0,0],
|
||
[0,0,<strong>1</strong>],
|
||
[1,0,0]]
|
||
<strong>输出:</strong>1
|
||
<strong>解释:</strong>(1,2) 是一个特殊位置,因为 mat[1][2] == 1 且所处的行和列上所有其他元素都是 0
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre><strong>输入:</strong>mat = [[<strong>1</strong>,0,0],
|
||
[0,<strong>1</strong>,0],
|
||
[0,0,<strong>1</strong>]]
|
||
<strong>输出:</strong>3
|
||
<strong>解释:</strong>(0,0), (1,1) 和 (2,2) 都是特殊位置
|
||
</pre>
|
||
|
||
<p><strong>示例 3:</strong></p>
|
||
|
||
<pre><strong>输入:</strong>mat = [[0,0,0,<strong>1</strong>],
|
||
[<strong>1</strong>,0,0,0],
|
||
[0,1,1,0],
|
||
[0,0,0,0]]
|
||
<strong>输出:</strong>2
|
||
</pre>
|
||
|
||
<p><strong>示例 4:</strong></p>
|
||
|
||
<pre><strong>输入:</strong>mat = [[0,0,0,0,0],
|
||
[<strong>1</strong>,0,0,0,0],
|
||
[0,<strong>1</strong>,0,0,0],
|
||
[0,0,<strong>1</strong>,0,0],
|
||
[0,0,0,1,1]]
|
||
<strong>输出:</strong>3
|
||
</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>rows == mat.length</code></li>
|
||
<li><code>cols == mat[i].length</code></li>
|
||
<li><code>1 <= rows, cols <= 100</code></li>
|
||
<li><code>mat[i][j]</code> 是 <code>0</code> 或 <code>1</code></li>
|
||
</ul>
|