1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/有效的数独 [valid-sudoku].html
2022-03-29 12:43:11 +08:00

62 lines
2.3 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>请你判断一个&nbsp;<code>9 x 9</code> 的数独是否有效。只需要<strong> 根据以下规则</strong> ,验证已经填入的数字是否有效即可。</p>
<ol>
<li>数字&nbsp;<code>1-9</code>&nbsp;在每一行只能出现一次。</li>
<li>数字&nbsp;<code>1-9</code>&nbsp;在每一列只能出现一次。</li>
<li>数字&nbsp;<code>1-9</code>&nbsp;在每一个以粗实线分隔的&nbsp;<code>3x3</code>&nbsp;宫内只能出现一次。(请参考示例图)</li>
</ol>
<p>&nbsp;</p>
<p><strong>注意:</strong></p>
<ul>
<li>一个有效的数独(部分已被填充)不一定是可解的。</li>
<li>只需要根据以上规则,验证已经填入的数字是否有效即可。</li>
<li>空白格用&nbsp;<code>'.'</code>&nbsp;表示。</li>
</ul>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<img src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2021/04/12/250px-sudoku-by-l2g-20050714svg.png" style="height:250px; width:250px" />
<pre>
<strong>输入:</strong>board =
[["5","3",".",".","7",".",".",".","."]
,["6",".",".","1","9","5",".",".","."]
,[".","9","8",".",".",".",".","6","."]
,["8",".",".",".","6",".",".",".","3"]
,["4",".",".","8",".","3",".",".","1"]
,["7",".",".",".","2",".",".",".","6"]
,[".","6",".",".",".",".","2","8","."]
,[".",".",".","4","1","9",".",".","5"]
,[".",".",".",".","8",".",".","7","9"]]
<strong>输出:</strong>true
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>board =
[["8","3",".",".","7",".",".",".","."]
,["6",".",".","1","9","5",".",".","."]
,[".","9","8",".",".",".",".","6","."]
,["8",".",".",".","6",".",".",".","3"]
,["4",".",".","8",".","3",".",".","1"]
,["7",".",".",".","2",".",".",".","6"]
,[".","6",".",".",".",".","2","8","."]
,[".",".",".","4","1","9",".",".","5"]
,[".",".",".",".","8",".",".","7","9"]]
<strong>输出:</strong>false
<strong>解释:</strong>除了第一行的第一个数字从<strong> 5</strong> 改为 <strong>8 </strong>以外,空格内其他数字均与 示例1 相同。 但由于位于左上角的 3x3 宫内有两个 8 存在, 因此这个数独是无效的。</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>board.length == 9</code></li>
<li><code>board[i].length == 9</code></li>
<li><code>board[i][j]</code> 是一位数字(<code>1-9</code>)或者 <code>'.'</code></li>
</ul>