[LeetCode] 4 Keys Keyboard 四键的键盘

Imagine you have a special keyboard with the following keys:

Key 1: (A): Print one ‘A‘ on screen.

Key 2: (Ctrl-A): Select the whole screen.

Key 3: (Ctrl-C): Copy selection to buffer.

Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed.

Now, you can only press the keyboard for N times (with the above four keys), find out the maximum numbers of ‘A‘ you can print on screen.

Example 1:

Input: N = 3
Output: 3
Explanation:
We can at most get 3 A‘s on screen by pressing following key sequence:
A, A, A

Example 2:

Input: N = 7
Output: 9
Explanation:
We can at most get 9 A‘s on screen by pressing following key sequence:
A, A, A, Ctrl A, Ctrl C, Ctrl V, Ctrl V

Note:

  1. 1 <= N <= 50
  2. Answers will be in the range of 32-bit signed integer.

s

时间: 2024-10-07 23:21:13

[LeetCode] 4 Keys Keyboard 四键的键盘的相关文章

[LeetCode] 2 Keys Keyboard 两键的键盘

Initially on a notepad only one character 'A' is present. You can perform two operations on this notepad for each step: Copy All: You can copy all the characters present on the notepad (partial copy is not allowed). Paste: You can paste the character

Leetcode 650.只有两个键的键盘

只有两个键的键盘 最初在一个记事本上只有一个字符 'A'.你每次可以对这个记事本进行两种操作: Copy All (复制全部) : 你可以复制这个记事本中的所有字符(部分的复制是不允许的). Paste (粘贴) : 你可以粘贴你上一次复制的字符. 给定一个数字 n .你需要使用最少的操作次数,在记事本中打印出恰好 n 个 'A'.输出能够打印出 n 个 'A' 的最少操作次数. 示例 1: 输入: 3 输出: 3 解释: 最初, 我们只有一个字符 'A'. 第 1 步, 我们使用 Copy A

如何使用alt键+数字键盘上的数字键打出特殊符号

如何使用alt键+数字键盘上的数字键打出特殊符号 有时当我需要画示意图说明一个问题,但是苦于没有合适的符号,因此,这篇博文将简单介绍一些特殊的符号方便自己以及大家使用. 实现原理很简单:所有的字符(包括字母.数字.汉字甚至是其他文字)在计算机内部都是以编码的形式存储的,比如其中小于127的称为标准ASCII编码,汉字也是有编码的,编码标准为GBK,在45687-63486之间存储着常用的6763个汉字.41377-43518存储者一些图形符号.43072-43424之间存储着一些非汉字符号.

650. 2 Keys Keyboard

public int minSteps(int n) { /* 由于只能复制全部或者一个,所以: 如果一个数不是质数,那么最快的就是由最大的公因子复制而来 如果一个数是质数,那么所有方式都大于等于全部由1复制而来 网上看了看这个规律都是观察得出的,所以直接背过: 两个键的键盘问题(只能全部复制或者粘贴问题): 非质数就考虑最大公因子,质数就直接返回n(当然考察质数也是需要循环判断没有因子) */ if (n <= 1) return 0; int[] dp = new int[n+1]; dp[

[LeetCode] Keyboard Row 键盘行

Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below. Example 1: Input: ["Hello", "Alaska", "Dad", "Peace"] Output: ["A

Leetcode刷题总结:650. 2 Keys Keyboard

题目: 求获取n个A的最小操作步骤的数目minStep Initially on a notepad only one character 'A' is present. You can perform two operations on this notepad for each step: Copy All: 只能全部复制,不能部分复制. Paste: 拷贝留在剪贴板上的字符 Given a number n. You have to get exactly n 'A' on the not

[leetcode-651-4 Keys Keyboard]

Imagine you have a special keyboard with the following keys: Key 1: (A): Prints one 'A' on screen. Key 2: (Ctrl-A): Select the whole screen. Key 3: (Ctrl-C): Copy selection to buffer. Key 4: (Ctrl-V): Print buffer on screen appending it after what ha

651. 4 Keys Keyboard复制粘贴获得的最大长度

[抄题]: Imagine you have a special keyboard with the following keys: Key 1: (A): Print one 'A' on screen. Key 2: (Ctrl-A): Select the whole screen. Key 3: (Ctrl-C): Copy selection to buffer. Key 4: (Ctrl-V): Print buffer on screen appending it after wh

LeetCode 18. 4Sum (四数之和)

Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target. Note: The solution set must not contain duplicate quadruplets. For exampl