1 Star 0 Fork 18

zcc/力扣题库(完整版)

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
faulty-keyboard.html 2.09 KB
一键复制 编辑 原始数据 按行查看 历史
小墨 提交于 2023-08-11 23:36 +08:00 . update
<p>Your laptop keyboard is faulty, and whenever you type a character <code>&#39;i&#39;</code> on it, it reverses the string that you have written. Typing other characters works as expected.</p>
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, and you type each character of <code>s</code> using your faulty keyboard.</p>
<p>Return <em>the final string that will be present on your laptop screen.</em></p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;string&quot;
<strong>Output:</strong> &quot;rtsng&quot;
<strong>Explanation:</strong>
After typing first character, the text on the screen is &quot;s&quot;.
After the second character, the text is &quot;st&quot;.
After the third character, the text is &quot;str&quot;.
Since the fourth character is an &#39;i&#39;, the text gets reversed and becomes &quot;rts&quot;.
After the fifth character, the text is &quot;rtsn&quot;.
After the sixth character, the text is &quot;rtsng&quot;.
Therefore, we return &quot;rtsng&quot;.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;poiinter&quot;
<strong>Output:</strong> &quot;ponter&quot;
<strong>Explanation:</strong>
After the first character, the text on the screen is &quot;p&quot;.
After the second character, the text is &quot;po&quot;.
Since the third character you type is an &#39;i&#39;, the text gets reversed and becomes &quot;op&quot;.
Since the fourth character you type is an &#39;i&#39;, the text gets reversed and becomes &quot;po&quot;.
After the fifth character, the text is &quot;pon&quot;.
After the sixth character, the text is &quot;pont&quot;.
After the seventh character, the text is &quot;ponte&quot;.
After the eighth character, the text is &quot;ponter&quot;.
Therefore, we return &quot;ponter&quot;.</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 100</code></li>
<li><code>s</code> consists of lowercase English letters.</li>
<li><code>s[0] != &#39;i&#39;</code></li>
</ul>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/tutuzhang0/leetcode-problemset.git
git@gitee.com:tutuzhang0/leetcode-problemset.git
tutuzhang0
leetcode-problemset
力扣题库(完整版)
master

搜索帮助