|
| 1 | +# [3324. 出现在屏幕上的字符串序列](https://leetcode.com/problems/find-the-sequence-of-strings-appeared-on-the-screen) |
| 2 | + |
| 3 | +🟠 <font color=#ffb800>Medium</font>  🔗 [`LeetCode`](https://leetcode.com/problems/find-the-sequence-of-strings-appeared-on-the-screen) |
| 4 | + |
| 5 | +## 题目 |
| 6 | + |
| 7 | +You are given a string `target`. |
| 8 | + |
| 9 | +Alice is going to type `target` on her computer using a special keyboard that |
| 10 | +has **only two** keys: |
| 11 | + |
| 12 | + * Key 1 appends the character `"a"` to the string on the screen. |
| 13 | + * Key 2 changes the **last** character of the string on the screen to its **next** character in the English alphabet. For example, `"c"` changes to `"d"` and `"z"` changes to `"a"`. |
| 14 | + |
| 15 | +**Note** that initially there is an _empty_ string `""` on the screen, so she |
| 16 | +can **only** press key 1. |
| 17 | + |
| 18 | +Return a list of _all_ strings that appear on the screen as Alice types |
| 19 | +`target`, in the order they appear, using the **minimum** key presses. |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | +**Example 1:** |
| 24 | + |
| 25 | +**Input:** target = "abc" |
| 26 | + |
| 27 | +**Output:** ["a","aa","ab","aba","abb","abc"] |
| 28 | + |
| 29 | +**Explanation:** |
| 30 | + |
| 31 | +The sequence of key presses done by Alice are: |
| 32 | + |
| 33 | + * Press key 1, and the string on the screen becomes `"a"`. |
| 34 | + * Press key 1, and the string on the screen becomes `"aa"`. |
| 35 | + * Press key 2, and the string on the screen becomes `"ab"`. |
| 36 | + * Press key 1, and the string on the screen becomes `"aba"`. |
| 37 | + * Press key 2, and the string on the screen becomes `"abb"`. |
| 38 | + * Press key 2, and the string on the screen becomes `"abc"`. |
| 39 | + |
| 40 | +**Example 2:** |
| 41 | + |
| 42 | +**Input:** target = "he" |
| 43 | + |
| 44 | +**Output:** ["a","b","c","d","e","f","g","h","ha","hb","hc","hd","he"] |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | +**Constraints:** |
| 49 | + |
| 50 | + * `1 <= target.length <= 400` |
| 51 | + * `target` consists only of lowercase English letters. |
| 52 | + |
| 53 | + |
| 54 | +## 题目大意 |
| 55 | + |
| 56 | +给你一个字符串 `target`。 |
| 57 | + |
| 58 | +Alice 将会使用一种特殊的键盘在她的电脑上输入 `target`,这个键盘**只有两个** 按键: |
| 59 | + |
| 60 | + * 按键 1:在屏幕上的字符串后追加字符 `'a'`。 |
| 61 | + * 按键 2:将屏幕上字符串的 **最后一个** 字符更改为英文字母表中的 **下一个** 字符。例如,`'c'` 变为 `'d'`,`'z'` 变为 `'a'`。 |
| 62 | + |
| 63 | +**注意** ,最初屏幕上是一个 _空_ 字符串 `""`,所以她**只能** 按按键 1。 |
| 64 | + |
| 65 | +请你考虑按键次数 **最少** 的情况,按字符串出现顺序,返回 Alice 输入 `target` 时屏幕上出现的所有字符串列表。 |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | +**示例 1:** |
| 70 | + |
| 71 | +**输入:** target = "abc" |
| 72 | + |
| 73 | +**输出:** ["a","aa","ab","aba","abb","abc"] |
| 74 | + |
| 75 | +**解释:** |
| 76 | + |
| 77 | +Alice 按键的顺序如下: |
| 78 | + |
| 79 | + * 按下按键 1,屏幕上的字符串变为 `"a"`。 |
| 80 | + * 按下按键 1,屏幕上的字符串变为 `"aa"`。 |
| 81 | + * 按下按键 2,屏幕上的字符串变为 `"ab"`。 |
| 82 | + * 按下按键 1,屏幕上的字符串变为 `"aba"`。 |
| 83 | + * 按下按键 2,屏幕上的字符串变为 `"abb"`。 |
| 84 | + * 按下按键 2,屏幕上的字符串变为 `"abc"`。 |
| 85 | + |
| 86 | +**示例 2:** |
| 87 | + |
| 88 | +**输入:** target = "he" |
| 89 | + |
| 90 | +**输出:** ["a","b","c","d","e","f","g","h","ha","hb","hc","hd","he"] |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | +**提示:** |
| 95 | + |
| 96 | + * `1 <= target.length <= 400` |
| 97 | + * `target` 仅由小写英文字母组成。 |
| 98 | + |
| 99 | + |
| 100 | +## 解题思路 |
| 101 | + |
| 102 | +#### 复杂度分析 |
| 103 | + |
| 104 | +- **时间复杂度**:`O()`, |
| 105 | +- **空间复杂度**:`O()`, |
| 106 | + |
| 107 | +## 代码 |
| 108 | + |
| 109 | +```javascript |
| 110 | + |
| 111 | +``` |
| 112 | + |
| 113 | +## 相关题目 |
| 114 | + |
| 115 | +<!-- prettier-ignore --> |
| 116 | +| 题号 | 标题 | 题解 | 标签 | 难度 | |
| 117 | +| :------: | :------ | :------: | :------ | :------ | |
| 118 | +| 500 | [键盘行](https://leetcode.com/problems/keyboard-row) | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) | <font color=#15bd66>Easy</font> | |
| 119 | + |
| 120 | +<style> |
| 121 | +.blue { |
| 122 | + background-color: #096dd9; |
| 123 | + padding: 0.25rem 0.5rem; |
| 124 | + margin: 0; |
| 125 | + font-size: 0.85em; |
| 126 | + border-radius: 3px; |
| 127 | + color: white; |
| 128 | + font-weight: 500; |
| 129 | +} |
| 130 | +table th:first-of-type { width: 10%; } |
| 131 | +table th:nth-of-type(2) { width: 35%; } |
| 132 | +table th:nth-of-type(3) { width: 10%; } |
| 133 | +table th:nth-of-type(4) { width: 35%; } |
| 134 | +table th:nth-of-type(5) { width: 10%; } |
| 135 | +</style> |
0 commit comments