1 Star 0 Fork 18

zcc/力扣题库(完整版)

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
find-the-k-th-character-in-string-game-i.html 2.12 KB
Copy Edit Raw Blame History
小墨 authored 2024-10-10 00:43 +08:00 . update
<p>Alice and Bob are playing a game. Initially, Alice has a string <code>word = &quot;a&quot;</code>.</p>
<p>You are given a <strong>positive</strong> integer <code>k</code>.</p>
<p>Now Bob will ask Alice to perform the following operation <strong>forever</strong>:</p>
<ul>
<li>Generate a new string by <strong>changing</strong> each character in <code>word</code> to its <strong>next</strong> character in the English alphabet, and <strong>append</strong> it to the <em>original</em> <code>word</code>.</li>
</ul>
<p>For example, performing the operation on <code>&quot;c&quot;</code> generates <code>&quot;cd&quot;</code> and performing the operation on <code>&quot;zb&quot;</code> generates <code>&quot;zbac&quot;</code>.</p>
<p>Return the value of the <code>k<sup>th</sup></code> character in <code>word</code>, after enough operations have been done for <code>word</code> to have <strong>at least</strong> <code>k</code> characters.</p>
<p><strong>Note</strong> that the character <code>&#39;z&#39;</code> can be changed to <code>&#39;a&#39;</code> in the operation.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">k = 5</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;b&quot;</span></p>
<p><strong>Explanation:</strong></p>
<p>Initially, <code>word = &quot;a&quot;</code>. We need to do the operation three times:</p>
<ul>
<li>Generated string is <code>&quot;b&quot;</code>, <code>word</code> becomes <code>&quot;ab&quot;</code>.</li>
<li>Generated string is <code>&quot;bc&quot;</code>, <code>word</code> becomes <code>&quot;abbc&quot;</code>.</li>
<li>Generated string is <code>&quot;bccd&quot;</code>, <code>word</code> becomes <code>&quot;abbcbccd&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">k = 10</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;c&quot;</span></p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= k &lt;= 500</code></li>
</ul>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/tutuzhang0/leetcode-problemset.git
git@gitee.com:tutuzhang0/leetcode-problemset.git
tutuzhang0
leetcode-problemset
力扣题库(完整版)
master

Search