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)/黑白翻转棋 [fHi6rV].md
2022-03-29 12:43:11 +08:00

43 lines
2.0 KiB
Markdown
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.

`n*m` 大小的棋盘中,有黑白两种棋子,黑棋记作字母 `"X"`, 白棋记作字母 `"O"`,空余位置记作 `"."`。当落下的棋子与其他相同颜色的棋子在行、列或对角线完全包围(中间不存在空白位置)另一种颜色的棋子,则可以翻转这些棋子的颜色。
![1.gif](https://pic.leetcode-cn.com/1630396029-eTgzpN-6da662e67368466a96d203f67bb6e793.gif){:height=170px}![2.gif](https://pic.leetcode-cn.com/1630396240-nMvdcc-8e4261afe9f60e05a4f740694b439b6b.gif){:height=170px}![3.gif](https://pic.leetcode-cn.com/1630396291-kEtzLL-6fcb682daeecb5c3f56eb88b23c81d33.gif){:height=170px}
「力扣挑战赛」黑白翻转棋项目中,将提供给选手一个未形成可翻转棋子的棋盘残局,其状态记作 `chessboard`。若下一步可放置一枚黑棋,请问选手最多能翻转多少枚白棋。
**注意:**
- 若翻转白棋成黑棋后,棋盘上仍存在可以翻转的白棋,将可以 **继续** 翻转白棋
- 输入数据保证初始棋盘状态无可以翻转的棋子且存在空余位置
**示例 1**
> 输入:`chessboard = ["....X.","....X.","XOOO..","......","......"]`
>
> 输出:`3`
>
> 解释:
> 可以选择下在 `[2,4]` 处,能够翻转白方三枚棋子。
**示例 2**
> 输入:`chessboard = [".X.",".O.","XO."]`
>
> 输出:`2`
>
> 解释:
> 可以选择下在 `[2,2]` 处,能够翻转白方两枚棋子。
![2126c1d21b1b9a9924c639d449cc6e65.gif](https://pic.leetcode-cn.com/1626683255-OBtBud-2126c1d21b1b9a9924c639d449cc6e65.gif)
**示例 3**
> 输入:`chessboard = [".......",".......",".......","X......",".O.....","..O....","....OOX"]`
>
> 输出:`4`
>
> 解释:
> 可以选择下在 `[6,3]` 处,能够翻转白方四枚棋子。
![803f2f04098b6174397d6c696f54d709.gif](https://pic.leetcode-cn.com/1630393770-Puyked-803f2f04098b6174397d6c696f54d709.gif)
**提示:**
- `1 <= chessboard.length, chessboard[i].length <= 8`
- `chessboard[i]` 仅包含 `"."、"O"``"X"`