1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-03 06:22:54 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-05-02 23:44:12 +08:00
parent 7ea03594b3
commit 2a71c78585
4790 changed files with 11696 additions and 10944 deletions

View File

@@ -12,7 +12,7 @@
"translatedContent": "<p>你正在参与祖玛游戏的一个变种。</p>\n\n<p>在这个祖玛游戏变体中,桌面上有 <strong>一排</strong> 彩球,每个球的颜色可能是:红色 <code>'R'</code>、黄色 <code>'Y'</code>、蓝色 <code>'B'</code>、绿色 <code>'G'</code> 或白色 <code>'W'</code> 。你的手中也有一些彩球。</p>\n\n<p>你的目标是 <strong>清空</strong> 桌面上所有的球。每一回合:</p>\n\n<ul>\n\t<li>从你手上的彩球中选出 <strong>任意一颗</strong> ,然后将其插入桌面上那一排球中:两球之间或这一排球的任一端。</li>\n\t<li>接着,如果有出现 <strong>三个或者三个以上</strong> 且 <strong>颜色相同</strong> 的球相连的话,就把它们移除掉。\n\t<ul>\n\t\t<li>如果这种移除操作同样导致出现三个或者三个以上且颜色相同的球相连,则可以继续移除这些球,直到不再满足移除条件。</li>\n\t</ul>\n\t</li>\n\t<li>如果桌面上所有球都被移除,则认为你赢得本场游戏。</li>\n\t<li>重复这个过程,直到你赢了游戏或者手中没有更多的球。</li>\n</ul>\n\n<p>给你一个字符串 <code>board</code> ,表示桌面上最开始的那排球。另给你一个字符串 <code>hand</code> ,表示手里的彩球。请你按上述操作步骤移除掉桌上所有球,计算并返回所需的 <strong>最少</strong> 球数。如果不能移除桌上所有的球,返回 <code>-1</code> 。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>board = \"WRRBBW\", hand = \"RB\"\n<strong>输出:</strong>-1\n<strong>解释:</strong>无法移除桌面上的所有球。可以得到的最好局面是:\n- 插入一个 'R' ,使桌面变为 WRR<em><strong>R</strong></em>BBW 。W<em><strong>RRR</strong></em>BBW -&gt; WBBW\n- 插入一个 'B' ,使桌面变为 WBB<em><strong>B</strong></em>W 。W<em><strong>BBB</strong></em>W -&gt; WW\n桌面上还剩着球没有其他球可以插入。</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>board = \"WWRRBBWW\", hand = \"WRBRW\"\n<strong>输出:</strong>2\n<strong>解释:</strong>要想清空桌面上的球,可以按下述步骤:\n- 插入一个 'R' ,使桌面变为 WWRR<strong><em>R</em></strong>BBWW 。WW<em><strong>RRR</strong></em>BBWW -&gt; WWBBWW\n- 插入一个 'B' ,使桌面变为 WWBB<em><strong>B</strong></em>WW 。WW<em><strong>BBB</strong></em>WW -&gt; <em><strong>WWWW</strong></em> -&gt; empty\n只需从手中出 2 个球就可以清空桌面。\n</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre>\n<strong>输入:</strong>board = \"G\", hand = \"GGGGG\"\n<strong>输出:</strong>2\n<strong>解释:</strong>要想清空桌面上的球,可以按下述步骤:\n- 插入一个 'G' ,使桌面变为 G<em><strong>G</strong></em> 。\n- 插入一个 'G' ,使桌面变为 GG<em><strong>G</strong></em> 。<em><strong>GGG</strong></em> -&gt; empty\n只需从手中出 2 个球就可以清空桌面。\n</pre>\n\n<p><strong>示例 4</strong></p>\n\n<pre>\n<strong>输入:</strong>board = \"RBYYBBRRB\", hand = \"YRBGB\"\n<strong>输出:</strong>3\n<strong>解释:</strong>要想清空桌面上的球,可以按下述步骤:\n- 插入一个 'Y' ,使桌面变为 RBYY<em><strong>Y</strong></em>BBRRB 。RB<em><strong>YYY</strong></em>BBRRB -&gt; R<em><strong>BBB</strong></em>RRB -&gt; <em><strong>RRR</strong></em>B -&gt; B\n- 插入一个 'B' ,使桌面变为 B<em><strong>B</strong></em> 。\n- 插入一个 'B' ,使桌面变为 BB<em><strong>B</strong></em> 。<em><strong>BBB</strong></em> -&gt; empty\n只需从手中出 3 个球就可以清空桌面。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= board.length &lt;= 16</code></li>\n\t<li><code>1 &lt;= hand.length &lt;= 5</code></li>\n\t<li><code>board</code> 和 <code>hand</code> 由字符 <code>'R'</code>、<code>'Y'</code>、<code>'B'</code>、<code>'G'</code> 和 <code>'W'</code> 组成</li>\n\t<li>桌面上一开始的球中,不会有三个及三个以上颜色相同且连着的球</li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Hard",
"likes": 252,
"likes": 255,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -155,7 +155,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"18.4K\", \"totalSubmission\": \"35.7K\", \"totalAcceptedRaw\": 18426, \"totalSubmissionRaw\": 35663, \"acRate\": \"51.7%\"}",
"stats": "{\"totalAccepted\": \"18.6K\", \"totalSubmission\": \"36.3K\", \"totalAcceptedRaw\": 18593, \"totalSubmissionRaw\": 36277, \"acRate\": \"51.3%\"}",
"hints": [],
"solution": null,
"status": null,