1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/矩阵中的幻方 [magic-squares-in-grid].html
2022-03-29 12:43:11 +08:00

39 lines
1.4 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p><code>3 x 3</code> 的幻方是一个填充有&nbsp;<strong><code>1</code><code>9</code>&nbsp;</strong> 的不同数字的 <code>3 x 3</code> 矩阵,其中每行,每列以及两条对角线上的各数之和都相等。</p>
<p>给定一个由整数组成的<code>row x col</code>&nbsp;<code>grid</code>,其中有多少个&nbsp;<code>3 × 3</code> 的 “幻方” 子矩阵?(每个子矩阵都是连续的)。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/09/11/magic_main.jpg" /></p>
<pre>
<strong>输入: </strong>grid = [[4,3,8,4],[9,5,1,9],[2,7,6,2]
<strong>输出: </strong>1
<strong>解释: </strong>
下面的子矩阵是一个 3 x 3 的幻方:
<img src="https://assets.leetcode.com/uploads/2020/09/11/magic_valid.jpg" />
而这一个不是:
<img src="https://assets.leetcode.com/uploads/2020/09/11/magic_invalid.jpg" />
总的来说,在本示例所给定的矩阵中只有一个 3 x 3 的幻方子矩阵。
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输出:</strong> grid = [[8]]
<strong>输入:</strong> 0
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>row == grid.length</code></li>
<li><code>col == grid[i].length</code></li>
<li><code>1 &lt;= row, col &lt;= 10</code></li>
<li><code>0 &lt;= grid[i][j] &lt;= 15</code></li>
</ul>