[抄题]:

Initially on a notepad only one character 'A' is present. You can perform two operations on this notepad for each step:

  1. Copy All: You can copy all the characters present on the notepad (partial copy is not allowed).
  2. Paste: You can paste the characters which are copied last time.

Given a number n. You have to get exactly n 'A' on the notepad by performing the minimum number of steps permitted. Output the minimum number of steps to get n 'A'.

Example 1:

Input: 3
Output: 3
Explanation:
Intitally, we have one character 'A'.
In step 1, we use Copy All operation.
In step 2, we use Paste operation to get 'AA'.
In step 3, we use Paste operation to get 'AAA'.

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

以为是dp数组,结果只需要稍微除一下就行了

[英文数据结构或算法,为什么不用别的数据结构或算法]:

[一句话思路]:

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

  1. totalSteps += singleSteps; 需要一直相加来积累一次性能走的最长步数,否则要走很多次

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

需要while循环一直相加的时候要注意点

[复杂度]:Time complexity: O(n) Space complexity: O(1)

[算法思想:迭代/递归/分治/贪心]:

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

[代码风格] :

[是否头一次写此类driver funcion的代码] :

[潜台词] :

class Solution {
public int minSteps(int n) {
//initialization: totalSteps = 0
int totalSteps = 0; //for loop for n
for (int singleSteps = 2; singleSteps <= n; singleSteps++) {
while (n % singleSteps == 0) {
totalSteps += singleSteps;
n /= singleSteps;
}
} return totalSteps; /*
singleSteps 2 2
totalSteps 2 4
n 2 1
*/
}
}

650. 2 Keys Keyboard复制粘贴的次数的更多相关文章

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

    [抄题]: Imagine you have a special keyboard with the following keys: Key 1: (A): Print one 'A' on scre ...

  2. [LeetCode] 650. 2 Keys Keyboard 两键的键盘

    Initially on a notepad only one character 'A' is present. You can perform two operations on this not ...

  3. [leetcode] 650. 2 Keys Keyboard (Medium)

    解法一: 暴力DFS搜索,对每一步进行复制还是粘贴的状态进行遍历. 注意剪枝的地方: 1.当前A数量大于目标数量,停止搜索 2.当前剪贴板数字大于等于A数量时,只搜索下一步为粘贴的状态. Runtim ...

  4. 【LeetCode】650. 2 Keys Keyboard 只有两个键的键盘(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 素数分解 日期 题目地址:https://le ...

  5. LC 650. 2 Keys Keyboard

    Initially on a notepad only one character 'A' is present. You can perform two operations on this not ...

  6. LeetCode 650 - 2 Keys Keyboard

    LeetCode 第650题 Initially on a notepad only one character 'A' is present. You can perform two operati ...

  7. 650. 2 Keys Keyboard

    Initially on a notepad only one character 'A' is present. You can perform two operations on this not ...

  8. [LeetCode] 651. 4 Keys Keyboard 四键的键盘

    Imagine you have a special keyboard with the following keys: Key 1: (A): Print one 'A' on screen. Ke ...

  9. [LeetCode] 4 Keys Keyboard 四键的键盘

    Imagine you have a special keyboard with the following keys: Key 1: (A): Print one 'A' on screen. Ke ...

随机推荐

  1. Oracle使用备忘

    初学Oracle,很多语句记不住,写在这里备忘. 1.查看某表空间的数据文件 select file_name 文件名, tablespace_name 表空间名, bytes 已使用大小M, max ...

  2. Linux之cp、rm、mv

    cp.rm.mv 命令功能: 复制文件或目录 命令格式: cp [OPTION]... [-T] SOURCE DEST cp [OPTION]... SOURCE... DIRECTORY cp [ ...

  3. Flask-ORM-数据库的对象关系映射模型-备忘

    ORM对象关系映射模型的特点: 优点 : 只需要面向对象编程, 不需要面向数据库编写代码. 对数据库的操作都转化成对类属性和方法的操作. 不用编写各种数据库的sql语句. 实现了数据模型与数据库的解耦 ...

  4. 测试技术/网游Bug分析/单机修改 视频教程

    早期做的一些视频,测试技术/Bug讲解/单机修改,有兴趣的同学自行下载看吧 由于是早期录制的,有口误多包涵... 链接: http://pan.baidu.com/s/1i5JUKPf 密码: a1x ...

  5. 解决Kubelet Pod启动CreatePodSandbox或RunPodSandbox异常方法

    新装Kubernetes,创建一个新Pod,启动Pod遇到CreatePodSandbox或RunPodSandbox异常.查看日志 # journalctl --since :: -u kubele ...

  6. IIS6.0+win2003部署MVC网站的一些问题

    安装iis,framework环境不谈.MVC网站部署 步骤: 1.为程序新建一个应用程序池(将default的那个程序池作为模板就可以了) 2.web服务扩展一些启用一些必要的服务 3.新建网站 描 ...

  7. 论气机之"左升右降"

      生命现象源于气机的出入升降运动. “出入废则神机化灭,升降息则气立孤危.故非出入,则无以生长壮老已:非升降,则无以生长化收藏”(<素问·六微旨大论>),升降是气机主要的运动形式之一,是 ...

  8. 【亲测显式等待】Selenium:元素等待的4种方法

    Selenium:元素等待的4种方法 1.使用Thread.sleep(),这是最笨的方法,但有时候也能用到而且很实用.   2.隐式等待,隐性等待是指当要查找元素,而这个元素没有马上出现时,告诉We ...

  9. VS 代码片段集

    片段1:用于线程执行代码,耗时操作时加载Loging; <?xml version="1.0" encoding="utf-8"?> <Cod ...

  10. Fiddler手机抓包软件简单使用--将h5效果显示在手机

    此文章是博主自己所写,转载请注明出处 一.简介 Fiddler是一个http协议调试代理工具,它能够记录并检查所有你的电脑和互联网之间的http通讯,设置断点,查看所有的“进出”Fiddler的数据. ...