1 Star 41 Fork 18

小墨/力扣题库(完整版)

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
find-the-sequence-of-strings-appeared-on-the-screen.html 2.49 KB
一键复制 编辑 原始数据 按行查看 历史
小墨 提交于 2024-11-07 00:20 +08:00 . update
<p>You are given a string <code>target</code>.</p>
<p>Alice is going to type <code>target</code> on her computer using a special keyboard that has <strong>only two</strong> keys:</p>
<ul>
<li>Key 1 appends the character <code>&quot;a&quot;</code> to the string on the screen.</li>
<li>Key 2 changes the <strong>last</strong> character of the string on the screen to its <strong>next</strong> character in the English alphabet. For example, <code>&quot;c&quot;</code> changes to <code>&quot;d&quot;</code> and <code>&quot;z&quot;</code> changes to <code>&quot;a&quot;</code>.</li>
</ul>
<p><strong>Note</strong> that initially there is an <em>empty</em> string <code>&quot;&quot;</code> on the screen, so she can <strong>only</strong> press key 1.</p>
<p>Return a list of <em>all</em> strings that appear on the screen as Alice types <code>target</code>, in the order they appear, using the <strong>minimum</strong> key presses.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">target = &quot;abc&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">[&quot;a&quot;,&quot;aa&quot;,&quot;ab&quot;,&quot;aba&quot;,&quot;abb&quot;,&quot;abc&quot;]</span></p>
<p><strong>Explanation:</strong></p>
<p>The sequence of key presses done by Alice are:</p>
<ul>
<li>Press key 1, and the string on the screen becomes <code>&quot;a&quot;</code>.</li>
<li>Press key 1, and the string on the screen becomes <code>&quot;aa&quot;</code>.</li>
<li>Press key 2, and the string on the screen becomes <code>&quot;ab&quot;</code>.</li>
<li>Press key 1, and the string on the screen becomes <code>&quot;aba&quot;</code>.</li>
<li>Press key 2, and the string on the screen becomes <code>&quot;abb&quot;</code>.</li>
<li>Press key 2, and the string on the screen becomes <code>&quot;abc&quot;</code>.</li>
</ul>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">target = &quot;he&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">[&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;,&quot;e&quot;,&quot;f&quot;,&quot;g&quot;,&quot;h&quot;,&quot;ha&quot;,&quot;hb&quot;,&quot;hc&quot;,&quot;hd&quot;,&quot;he&quot;]</span></p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= target.length &lt;= 400</code></li>
<li><code>target</code> consists only of lowercase English letters.</li>
</ul>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/coder-xiaomo/leetcode-problemset.git
git@gitee.com:coder-xiaomo/leetcode-problemset.git
coder-xiaomo
leetcode-problemset
力扣题库(完整版)
master

搜索帮助