From 4bd1e15a11c22047325c929c03b62caa87031cab Mon Sep 17 00:00:00 2001 From: AC_Oier Date: Fri, 2 Dec 2022 15:41:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8feat:=20add=201769=20&=20678=20&?= =?UTF-8?q?=201601=20&=20131?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...33\345\210\266\346\236\232\344\270\276.md" | 2 +- ...10\344\270\255\347\255\211\357\274\211.md" | 1 + ...10\344\270\255\347\255\211\357\274\211.md" | 10 +- ...10\345\233\260\351\232\276\357\274\211.md" | 6 +- ...10\345\233\260\351\232\276\357\274\211.md" | 6 +- ...10\344\270\255\347\255\211\357\274\211.md" | 114 ++++++++++++++++++ ...10\344\270\255\347\255\211\357\274\211.md" | 2 + 7 files changed, 129 insertions(+), 12 deletions(-) create mode 100644 "LeetCode/1761-1770/1769. \347\247\273\345\212\250\346\211\200\346\234\211\347\220\203\345\210\260\346\257\217\344\270\252\347\233\222\345\255\220\346\211\200\351\234\200\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260\357\274\210\344\270\255\347\255\211\357\274\211.md" diff --git "a/Index/\344\272\214\350\277\233\345\210\266\346\236\232\344\270\276.md" "b/Index/\344\272\214\350\277\233\345\210\266\346\236\232\344\270\276.md" index 24702c86..472f62e7 100644 --- "a/Index/\344\272\214\350\277\233\345\210\266\346\236\232\344\270\276.md" +++ "b/Index/\344\272\214\350\277\233\345\210\266\346\236\232\344\270\276.md" @@ -4,6 +4,6 @@ | [784. 字母大小写全排列](https://leetcode.cn/problems/letter-case-permutation/) | [LeetCode 题解链接](https://leetcode.cn/problems/letter-case-permutation/solution/by-ac_oier-x7f0/) | 中等 | 🤩🤩🤩🤩 | | [805. 数组的均值分割](https://leetcode.cn/problems/split-array-with-same-average/) | [LeetCode 题解链接](https://leetcode.cn/problems/split-array-with-same-average/solution/gong-shui-san-xie-by-ac_oier-flsd/) | 困难 | 🤩🤩🤩🤩 | | [1239. 串联字符串的最大长度](https://leetcode-cn.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters/solution/gong-shui-san-xie-yi-ti-san-jie-jian-zhi-nfeb/) | 中等 | 🤩🤩🤩 | -| [1601. 最多可达成的换楼请求数目](https://leetcode-cn.com/problems/maximum-number-of-achievable-transfer-requests/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/maximum-number-of-achievable-transfer-requests/solution/gong-shui-san-xie-er-jin-zhi-mei-ju-by-a-enef/) | 中等 | 🤩🤩🤩🤩 | +| [1601. 最多可达成的换楼请求数目](https://leetcode-cn.com/problems/maximum-number-of-achievable-transfer-requests/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/maximum-number-of-achievable-transfer-requests/solution/gong-shui-san-xie-er-jin-zhi-mei-ju-by-a-enef/) | 困难 | 🤩🤩🤩🤩 | | [2044. 统计按位或能得到最大值的子集数目](https://leetcode-cn.com/problems/count-number-of-maximum-bitwise-or-subsets/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/count-number-of-maximum-bitwise-or-subsets/solution/by-ac_oier-dos6/) | 困难 | 🤩🤩🤩🤩 | diff --git "a/LeetCode/1-10/5. \346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262\357\274\210\344\270\255\347\255\211\357\274\211.md" "b/LeetCode/1-10/5. \346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262\357\274\210\344\270\255\347\255\211\357\274\211.md" index f0b4ed51..b18bffbc 100644 --- "a/LeetCode/1-10/5. \346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262\357\274\210\344\270\255\347\255\211\357\274\211.md" +++ "b/LeetCode/1-10/5. \346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262\357\274\210\344\270\255\347\255\211\357\274\211.md" @@ -156,6 +156,7 @@ class Solution { * 空间复杂度:$O(1)$ --- + ### 总结 今天这道题目,三叶除了提供常规的、时间复杂度为 $O(n^2)$ 的朴素解法以外,还给你提供了关于「回文串」的最优解 Manacher 算法模板,建议有余力的同学可以背过。 diff --git "a/LeetCode/131-140/131. \345\210\206\345\211\262\345\233\236\346\226\207\344\270\262\357\274\210\344\270\255\347\255\211\357\274\211.md" "b/LeetCode/131-140/131. \345\210\206\345\211\262\345\233\236\346\226\207\344\270\262\357\274\210\344\270\255\347\255\211\357\274\211.md" index fdf5a58d..c76ee8d1 100644 --- "a/LeetCode/131-140/131. \345\210\206\345\211\262\345\233\236\346\226\207\344\270\262\357\274\210\344\270\255\347\255\211\357\274\211.md" +++ "b/LeetCode/131-140/131. \345\210\206\345\211\262\345\233\236\346\226\207\344\270\262\357\274\210\344\270\255\347\255\211\357\274\211.md" @@ -6,11 +6,11 @@ Tag : 「回文串」、「回溯算法」、「动态规划」 -给你一个字符串 s,请你将 s 分割成一些子串,使每个子串都是 回文串 。返回 s 所有可能的分割方案。 - -回文串 是正着读和反着读都一样的字符串。 +给你一个字符串 `s`,请你将 `s` 分割成一些子串,使每个子串都是 回文串 。 +返回 `s` 所有可能的分割方案。 +回文串 是正着读和反着读都一样的字符串。 示例 1: ``` @@ -24,8 +24,8 @@ Tag : 「回文串」、「回溯算法」、「动态规划」 ``` 提示: -* 1 <= s.length <= 16 -* s 仅由小写英文字母组成 +* $1 <= s.length <= 16$ +* `s` 仅由小写英文字母组成 --- diff --git "a/LeetCode/131-140/132. \345\210\206\345\211\262\345\233\236\346\226\207\344\270\262 II\357\274\210\345\233\260\351\232\276\357\274\211.md" "b/LeetCode/131-140/132. \345\210\206\345\211\262\345\233\236\346\226\207\344\270\262 II\357\274\210\345\233\260\351\232\276\357\274\211.md" index 2a49b53f..4056855a 100644 --- "a/LeetCode/131-140/132. \345\210\206\345\211\262\345\233\236\346\226\207\344\270\262 II\357\274\210\345\233\260\351\232\276\357\274\211.md" +++ "b/LeetCode/131-140/132. \345\210\206\345\211\262\345\233\236\346\226\207\344\270\262 II\357\274\210\345\233\260\351\232\276\357\274\211.md" @@ -6,7 +6,7 @@ Tag : 「回文串」、「线性 DP」 -给你一个字符串 s,请你将 s 分割成一些子串,使每个子串都是回文。 +给你一个字符串 `s`,请你将 `s` 分割成一些子串,使每个子串都是回文。 返回符合要求的 最少分割次数 。 @@ -28,8 +28,8 @@ Tag : 「回文串」、「线性 DP」 ``` 提示: -* 1 <= s.length <= 2000 -* s 仅由小写英文字母组成 +* $1 <= s.length <= 2000$ +* `s` 仅由小写英文字母组成 --- diff --git "a/LeetCode/1601-1610/1601. \346\234\200\345\244\232\345\217\257\350\276\276\346\210\220\347\232\204\346\215\242\346\245\274\350\257\267\346\261\202\346\225\260\347\233\256\357\274\210\345\233\260\351\232\276\357\274\211.md" "b/LeetCode/1601-1610/1601. \346\234\200\345\244\232\345\217\257\350\276\276\346\210\220\347\232\204\346\215\242\346\245\274\350\257\267\346\261\202\346\225\260\347\233\256\357\274\210\345\233\260\351\232\276\357\274\211.md" index 0dfe5fbf..19c7e67a 100644 --- "a/LeetCode/1601-1610/1601. \346\234\200\345\244\232\345\217\257\350\276\276\346\210\220\347\232\204\346\215\242\346\245\274\350\257\267\346\261\202\346\225\260\347\233\256\357\274\210\345\233\260\351\232\276\357\274\211.md" +++ "b/LeetCode/1601-1610/1601. \346\234\200\345\244\232\345\217\257\350\276\276\346\210\220\347\232\204\346\215\242\346\245\274\350\257\267\346\261\202\346\225\260\347\233\256\357\274\210\345\233\260\351\232\276\357\274\211.md" @@ -6,7 +6,7 @@ Tag : 「二进制枚举」 -我们有 n 栋楼,编号从 0 到 n - 1 。每栋楼有若干员工。由于现在是换楼的季节,部分员工想要换一栋楼居住。 +我们有 `n` 栋楼,编号从 `0` 到 `n - 1` 。每栋楼有若干员工。由于现在是换楼的季节,部分员工想要换一栋楼居住。 给你一个数组 $requests$ ,其中 $requests[i] = [from_i, to_i]$ ,表示一个员工请求从编号为 $from_i$ 的楼搬到编号为 $to_i$ 的楼。 @@ -68,7 +68,7 @@ Tag : 「二进制枚举」 我们枚举所有的 $state$ 并进行合法性检查,从中选择出包含请求数的最多(二进制表示中包含 $1$ 个数最多)的合法 $state$,其包含的请求数量即是答案。 -其中统计 $state$ 中 $1$ 的个数可以使用 `lowbit`,复杂度为 $O(m)$,判断合法性则直接模拟即可(统计每座建筑的进出数量,最后判定进出数不相等的建筑数量是为 $0$),复杂度为 $O(m)$,整体计算量为不超过 $2*10^6$,可以过。 +其中统计 $state$ 中 $1$ 的个数可以使用 `lowbit`,复杂度为 $O(m)$,判断合法性则直接模拟即可(统计每座建筑的进出数量,最后判定进出数不相等的建筑数量是为 $0$),复杂度为 $O(m)$,整体计算量为不超过 $2 \times 10^6$,可以过。 代码: ```Java @@ -103,7 +103,7 @@ class Solution { } } ``` -* 时间复杂度:令 $m$ 为 $requests$ 长度,共有 $2^m$ 种选择状态,计算每个状态的所包含的问题数量复杂度为 $O(m)$,计算某个状态是否合法复杂度为 $O(m)$;整体复杂度为 $O(2^m * m)$ +* 时间复杂度:令 $m$ 为 $requests$ 长度,共有 $2^m$ 种选择状态,计算每个状态的所包含的问题数量复杂度为 $O(m)$,计算某个状态是否合法复杂度为 $O(m)$;整体复杂度为 $O(2^m \times m)$ * 空间复杂度:$O(n)$ --- diff --git "a/LeetCode/1761-1770/1769. \347\247\273\345\212\250\346\211\200\346\234\211\347\220\203\345\210\260\346\257\217\344\270\252\347\233\222\345\255\220\346\211\200\351\234\200\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260\357\274\210\344\270\255\347\255\211\357\274\211.md" "b/LeetCode/1761-1770/1769. \347\247\273\345\212\250\346\211\200\346\234\211\347\220\203\345\210\260\346\257\217\344\270\252\347\233\222\345\255\220\346\211\200\351\234\200\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260\357\274\210\344\270\255\347\255\211\357\274\211.md" new file mode 100644 index 00000000..afb738d8 --- /dev/null +++ "b/LeetCode/1761-1770/1769. \347\247\273\345\212\250\346\211\200\346\234\211\347\220\203\345\210\260\346\257\217\344\270\252\347\233\222\345\255\220\346\211\200\351\234\200\347\232\204\346\234\200\345\260\217\346\223\215\344\275\234\346\225\260\357\274\210\344\270\255\347\255\211\357\274\211.md" @@ -0,0 +1,114 @@ +### 题目描述 + +这是 LeetCode 上的 **[1769. 移动所有球到每个盒子所需的最小操作数]()** ,难度为 **中等**。 + +Tag : 「模拟」 + + + +有 `n` 个盒子。给你一个长度为 `n` 的二进制字符串 `boxes`,其中 `boxes[i]` 的值为 `'0'` 表示第 `i` 个盒子是 空 的,而 `boxes[i]` 的值为 `'1'` 表示盒子里有 一个 小球。 + +在一步操作中,你可以将 一个 小球从某个盒子移动到一个与之相邻的盒子中。第 `i` 个盒子和第 `j` 个盒子相邻需满足 `abs(i - j) == 1`。注意,操作执行后,某些盒子中可能会存在不止一个小球。 + +返回一个长度为 `n` 的数组 `answer`,其中 `answer[i]` 是将所有小球移动到第 `i` 个盒子所需的 最小 操作数。 + +每个 `answer[i]` 都需要根据盒子的 初始状态 进行计算。 + +示例 1: +``` +输入:boxes = "110" + +输出:[1,1,3] + +解释:每个盒子对应的最小操作数如下: +1) 第 1 个盒子:将一个小球从第 2 个盒子移动到第 1 个盒子,需要 1 步操作。 +2) 第 2 个盒子:将一个小球从第 1 个盒子移动到第 2 个盒子,需要 1 步操作。 +3) 第 3 个盒子:将一个小球从第 1 个盒子移动到第 3 个盒子,需要 2 步操作。将一个小球从第 2 个盒子移动到第 3 个盒子,需要 1 步操作。共计 3 步操作。 +``` +示例 2: +``` +输入:boxes = "001011" + +输出:[11,8,5,4,3,4] +``` + +提示: +* $n = boxes.length$ +* $1 <= n <= 2000$ +* `boxes[i]` 为 `'0'` 或 `'1'` + +--- + +### 模拟 + +预处理两个与 `boxes` 等长的数组 `l` 和 `r`:$l[i]$ 和 $r[i]$ 分别代表「将 $[0, i]$ 的小球移动到位置 $i$」以及「将 $[i, n - 1]$ 的小球移动到位置 $i$」所需要的步数。 + +所求的答案数组 `ans` 与数组 `l` 和 `r` 的关系为:$ans[i] = l[i] + r[i]$。 + +预处理两数组是简单的:分别从两个方向遍历 `boxes`,使用变量 `cur` 代表当前处理到的前缀/后缀的小球总个数,变量 `step` 代表将当前所有前缀/后缀小球移动到位置 $i$ 所需要的步数。 + +Java 代码: +```Java +class Solution { + public int[] minOperations(String boxes) { + int n = boxes.length(); + int[] l = new int[n + 10], r = new int[n + 10]; + for (int i = 0, cur = 0, step = 0; i < n; i++) { + step += cur; cur += boxes.charAt(i) - '0'; l[i] = step; + } + for (int i = n - 1, cur = 0, step = 0; i >= 0; i--) { + step += cur; cur += boxes.charAt(i) - '0'; r[i] = step; + } + int[] ans = new int[n]; + for (int i = 0; i < n; i++) ans[i] = l[i] + r[i]; + return ans; + } +} +``` +TypeScript 代码: +```TypeScript +function minOperations(boxes: string): number[] { + const n = boxes.length + const l = new Array(n + 10).fill(0), r = new Array(n + 10).fill(0) + for (let i = 0, cur = 0, step = 0; i < n; i++) { + step += cur; cur += boxes[i] == '1' ? 1 : 0; l[i] = step; + } + for (let i = n - 1, cur = 0, step = 0; i >= 0; i--) { + step += cur; cur += boxes[i] == '1' ? 1 : 0; r[i] = step; + } + const ans = new Array(n).fill(0) + for (let i = 0; i < n; i++) ans[i] = l[i] + r[i] + return ans +} +``` +Python 代码: +```Python +class Solution: + def minOperations(self, boxes: str) -> List[int]: + n = len(boxes) + l, r = [0] * n, [0] * n + step, cur = 0, 0 + for i in range(n): + step, cur = step + cur, cur + 1 if boxes[i] == '1' else cur + l[i] = step + step, cur = 0, 0 + for i in range(n - 1, -1, -1): + step, cur = step + cur, cur + 1 if boxes[i] == '1' else cur + r[i] = step + return [l[i] + r[i] for i in range(n)] +``` +* 时间复杂度:$O(n)$ +* 空间复杂度:$O(n)$ + +--- + +### 最后 + +这是我们「刷穿 LeetCode」系列文章的第 `No.1769` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完。 + +在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。 + +为了方便各位同学能够电脑上进行调试和提交代码,我建立了相关的仓库:https://github.com/SharingSource/LogicStack-LeetCode 。 + +在仓库地址里,你可以看到系列文章的题解链接、系列文章的相应代码、LeetCode 原题链接和其他优选题解。 + diff --git "a/LeetCode/671-680/678. \346\234\211\346\225\210\347\232\204\346\213\254\345\217\267\345\255\227\347\254\246\344\270\262\357\274\210\344\270\255\347\255\211\357\274\211.md" "b/LeetCode/671-680/678. \346\234\211\346\225\210\347\232\204\346\213\254\345\217\267\345\255\227\347\254\246\344\270\262\357\274\210\344\270\255\347\255\211\357\274\211.md" index 770907c1..db691046 100644 --- "a/LeetCode/671-680/678. \346\234\211\346\225\210\347\232\204\346\213\254\345\217\267\345\255\227\347\254\246\344\270\262\357\274\210\344\270\255\347\255\211\357\274\211.md" +++ "b/LeetCode/671-680/678. \346\234\211\346\225\210\347\232\204\346\213\254\345\217\267\345\255\227\347\254\246\344\270\262\357\274\210\344\270\255\347\255\211\357\274\211.md" @@ -4,6 +4,8 @@ Tag : 「有效括号问题」、「动态规划」、「模拟」 + + 给定一个只包含三种字符的字符串:`(` ,`)` 和 `*`,写一个函数来检验这个字符串是否为有效字符串。 有效字符串具有如下规则: From 1c742cae04c8be08b9ef6c2e969eb9a0e3f994d5 Mon Sep 17 00:00:00 2001 From: AC_Oier Date: Tue, 6 Dec 2022 11:53:40 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8feat:=20add=20650=20&=20526?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "Index/\344\272\214\345\210\206.md" | 1 - ...0\256\241\347\256\227\345\207\240\344\275\225.md" | 1 + ...7\274\210\344\270\255\347\255\211\357\274\211.md" | 2 +- ...7\274\210\344\270\255\347\255\211\357\274\211.md" | 12 +++++++----- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git "a/Index/\344\272\214\345\210\206.md" "b/Index/\344\272\214\345\210\206.md" index 1edd4c79..811edc60 100644 --- "a/Index/\344\272\214\345\210\206.md" +++ "b/Index/\344\272\214\345\210\206.md" @@ -77,4 +77,3 @@ | [剑指 Offer 53 - II. 0~n-1中缺失的数字](https://leetcode.cn/problems/que-shi-de-shu-zi-lcof/) | [LeetCode 题解链接](https://leetcode.cn/problems/que-shi-de-shu-zi-lcof/solution/by-ac_oier-gs6q/) | 简单 | 🤩🤩🤩🤩🤩 | | [剑指 Offer II 008. 和大于等于 target 的最短子数组](https://leetcode.cn/problems/2VG8Kg/) | [LeetCode 题解链接](https://leetcode.cn/problems/2VG8Kg/solution/by-ac_oier-vw5r/) | 中等 | 🤩🤩🤩🤩 | | [剑指 Offer II 069. 山峰数组的顶部](https://leetcode-cn.com/problems/B1IidL/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/B1IidL/solution/gong-shui-san-xie-er-fen-san-fen-ji-zhi-lc8zl/) | 简单 | 🤩🤩🤩🤩🤩 | - diff --git "a/Index/\350\256\241\347\256\227\345\207\240\344\275\225.md" "b/Index/\350\256\241\347\256\227\345\207\240\344\275\225.md" index d46ece23..1b30ebb2 100644 --- "a/Index/\350\256\241\347\256\227\345\207\240\344\275\225.md" +++ "b/Index/\350\256\241\347\256\227\345\207\240\344\275\225.md" @@ -3,4 +3,5 @@ | [587. 安装栅栏](https://leetcode-cn.com/problems/erect-the-fence/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/erect-the-fence/solution/by-ac_oier-4xuu/) | 困难 | 🤩🤩🤩🤩🤩 | | [593. 有效的正方形](https://leetcode.cn/problems/valid-square/) | [LeetCode 题解链接](https://leetcode.cn/problems/valid-square/solution/by-ac_oier-lwdf/) | 中等 | 🤩🤩🤩🤩🤩 | | [1037. 有效的回旋镖](https://leetcode.cn/problems/valid-boomerang/) | [LeetCode 题解链接](https://leetcode.cn/problems/valid-boomerang/solution/by-ac_oier-eory/) | 简单 | 🤩🤩🤩🤩🤩 | +| [1610. 可见点的最大数目](https://leetcode.cn/problems/maximum-number-of-visible-points/) | [LeetCode 题解链接](https://leetcode.cn/problems/maximum-number-of-visible-points/solution/gong-shui-san-xie-qiu-ji-jiao-ji-he-ti-b-0bid/) | 困难 | 🤩🤩🤩🤩 | diff --git "a/LeetCode/521-530/526. \344\274\230\347\276\216\347\232\204\346\216\222\345\210\227\357\274\210\344\270\255\347\255\211\357\274\211.md" "b/LeetCode/521-530/526. \344\274\230\347\276\216\347\232\204\346\216\222\345\210\227\357\274\210\344\270\255\347\255\211\357\274\211.md" index 93229846..07c34f1c 100644 --- "a/LeetCode/521-530/526. \344\274\230\347\276\216\347\232\204\346\216\222\345\210\227\357\274\210\344\270\255\347\255\211\357\274\211.md" +++ "b/LeetCode/521-530/526. \344\274\230\347\276\216\347\232\204\346\216\222\345\210\227\357\274\210\344\270\255\347\255\211\357\274\211.md" @@ -31,7 +31,7 @@ Tag : 「位运算」、「状压 DP」、「动态规划」 ``` 说明: -* N 是一个正整数,并且不会超过15。 +* $N$ 是一个正整数,并且不会超过 $15$。 --- diff --git "a/LeetCode/641-650/650. \345\217\252\346\234\211\344\270\244\344\270\252\351\224\256\347\232\204\351\224\256\347\233\230\357\274\210\344\270\255\347\255\211\357\274\211.md" "b/LeetCode/641-650/650. \345\217\252\346\234\211\344\270\244\344\270\252\351\224\256\347\232\204\351\224\256\347\233\230\357\274\210\344\270\255\347\255\211\357\274\211.md" index b62d26d5..6a837043 100644 --- "a/LeetCode/641-650/650. \345\217\252\346\234\211\344\270\244\344\270\252\351\224\256\347\232\204\351\224\256\347\233\230\357\274\210\344\270\255\347\255\211\357\274\211.md" +++ "b/LeetCode/641-650/650. \345\217\252\346\234\211\344\270\244\344\270\252\351\224\256\347\232\204\351\224\256\347\233\230\357\274\210\344\270\255\347\255\211\357\274\211.md" @@ -4,12 +4,14 @@ Tag : 「动态规划」、「线性 DP」、「数学」、「打表」 -最初记事本上只有一个字符 'A' 。你每次可以对这个记事本进行两种操作: -* Copy All(复制全部):复制这个记事本中的所有字符(不允许仅复制部分字符)。 -* Paste(粘贴):粘贴 上一次 复制的字符。 -给你一个数字 n ,你需要使用最少的操作次数,在记事本上输出 恰好 n 个 'A' 。返回能够打印出 n 个 'A' 的最少操作次数。 +最初记事本上只有一个字符 `'A'` 。你每次可以对这个记事本进行两种操作: + +* `Copy All(复制全部)`:复制这个记事本中的所有字符(不允许仅复制部分字符)。 +* `Paste(粘贴)`:粘贴 上一次 复制的字符。 + +给你一个数字 `n` ,你需要使用最少的操作次数,在记事本上输出 恰好 `n` 个 `'A'` 。返回能够打印出 `n` 个 `'A'` 的最少操作次数。 示例 1: @@ -32,7 +34,7 @@ Tag : 「动态规划」、「线性 DP」、「数学」、「打表」 ``` 提示: -* 1 <= n <= 1000 +* $1 <= n <= 1000$ ---