1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-11-03 03:03:10 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (Chinese)/使用特殊打字机键入单词的最少时间 [minimum-time-to-type-word-using-special-typewriter].html
2022-03-29 12:43:11 +08:00

68 lines
2.3 KiB
HTML
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.

<p>有一个特殊打字机,它由一个 <strong>圆盘</strong> 和一个 <strong>指针</strong>&nbsp;组成, 圆盘上标有小写英文字母&nbsp;<code>'a'</code>&nbsp;<code>'z'</code><strong>只有</strong>&nbsp;当指针指向某个字母时,它才能被键入。指针 <strong>初始时</strong>&nbsp;指向字符 <code>'a'</code>&nbsp;</p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/07/31/chart.jpg" style="width: 530px; height: 410px;" />
<p>每一秒钟,你可以执行以下操作之一:</p>
<ul>
<li>将指针 <strong>顺时针</strong>&nbsp;或者 <b>逆时针</b>&nbsp;移动一个字符。</li>
<li>键入指针 <strong>当前</strong>&nbsp;指向的字符。</li>
</ul>
<p>给你一个字符串&nbsp;<code>word</code>&nbsp;,请你返回键入&nbsp;<code>word</code>&nbsp;所表示单词的 <b>最少</b>&nbsp;秒数&nbsp;</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<b>输入:</b>word = "abc"
<b>输出:</b>5
<strong>解释:
</strong>单词按如下操作键入:
- 花 1 秒键入字符 'a' in 1 ,因为指针初始指向 'a' ,故不需移动指针。
- 花 1 秒将指针顺时针移到 'b' 。
- 花 1 秒键入字符 'b' 。
- 花 1 秒将指针顺时针移到 'c' 。
- 花 1 秒键入字符 'c' 。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<b>输入:</b>word = "bza"
<b>输出:</b>7
<strong>解释:
</strong>单词按如下操作键入:
- 花 1 秒将指针顺时针移到 'b' 。
- 花 1 秒键入字符 'b' 。
- 花 2 秒将指针逆时针移到 'z' 。
- 花 1 秒键入字符 'z' 。
- 花 1 秒将指针顺时针移到 'a' 。
- 花 1 秒键入字符 'a' 。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<b>输入:</b>word = "zjpc"
<b>输出:</b>34
<strong>解释:</strong>
单词按如下操作键入:
- 花 1 秒将指针逆时针移到 'z' 。
- 花 1 秒键入字符 'z' 。
- 花 10 秒将指针顺时针移到 'j' 。
- 花 1 秒键入字符 'j' 。
- 花 6 秒将指针顺时针移到 'p' 。
- 花 1 秒键入字符 'p' 。
- 花 13 秒将指针逆时针移到 'c' 。
- 花 1 秒键入字符 'c' 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= word.length &lt;= 100</code></li>
<li><code>word</code>&nbsp;只包含小写英文字母。</li>
</ul>