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)/有效的井字游戏 [valid-tic-tac-toe-state].html
2022-03-29 12:43:11 +08:00

50 lines
2.1 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>board</code> 表示井字游戏的棋盘。当且仅当在井字游戏过程中,棋盘有可能达到 <code>board</code> 所显示的状态时,才返回 <code>true</code></p>
<p>井字游戏的棋盘是一个 <code>3 x 3</code> 数组,由字符 <code>' '</code><code>'X'</code><code>'O'</code> 组成。字符 <code>' '</code> 代表一个空位。</p>
<p>以下是井字游戏的规则:</p>
<ul>
<li>玩家轮流将字符放入空位(<code>' '</code>)中。</li>
<li>玩家 1 总是放字符 <code>'X'</code> ,而玩家 2 总是放字符 <code>'O'</code></li>
<li><code>'X'</code><code>'O'</code> 只允许放置在空位中,不允许对已放有字符的位置进行填充。</li>
<li>当有 3 个相同(且非空)的字符填充任何行、列或对角线时,游戏结束。</li>
<li>当所有位置非空时,也算为游戏结束。</li>
<li>如果游戏结束,玩家不允许再放置字符。</li>
</ul>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/05/15/tictactoe1-grid.jpg" style="width: 253px; height: 253px;" />
<pre>
<strong>输入:</strong>board = ["O "," "," "]
<strong>输出:</strong>false
<strong>解释:</strong>玩家 1 总是放字符 "X" 。
</pre>
<p><strong>示例 2</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/05/15/tictactoe2-grid.jpg" style="width: 253px; height: 253px;" />
<pre>
<strong>输入:</strong>board = ["XOX"," X "," "]
<strong>输出:</strong>false
<strong>解释:</strong>玩家应该轮流放字符。
</pre>
<p><strong>示例 3:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/05/15/tictactoe4-grid.jpg" style="width: 253px; height: 253px;" />
<pre>
<strong>输入:</strong>board = ["XOX","O O","XOX"]
<strong>输出:</strong>true
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>board.length == 3</code></li>
<li><code>board[i].length == 3</code></li>
<li><code>board[i][j]</code><code>'X'</code><code>'O'</code><code>' '</code></li>
</ul>