Skip to content

Commit 4795b71

Browse files
committed
Add solution #650
1 parent cfed41a commit 4795b71

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@
489489
647|[Palindromic Substrings](./0647-palindromic-substrings.js)|Medium|
490490
648|[Replace Words](./0648-replace-words.js)|Medium|
491491
649|[Dota2 Senate](./0649-dota2-senate.js)|Medium|
492+
650|[2 Keys Keyboard](./0650-2-keys-keyboard.js)|Medium|
492493
653|[Two Sum IV - Input is a BST](./0653-two-sum-iv-input-is-a-bst.js)|Easy|
493494
654|[Maximum Binary Tree](./0654-maximum-binary-tree.js)|Medium|
494495
680|[Valid Palindrome II](./0680-valid-palindrome-ii.js)|Easy|

solutions/0650-2-keys-keyboard.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* 650. 2 Keys Keyboard
3+
* https://leetcode.com/problems/2-keys-keyboard/
4+
* Difficulty: Medium
5+
*
6+
* There is only one character 'A' on the screen of a notepad. You can perform one of two
7+
* operations on this notepad for each step:
8+
* - Copy All: You can copy all the characters present on the screen (a partial copy is
9+
* not allowed).
10+
* - Paste: You can paste the characters which are copied last time.
11+
*
12+
* Given an integer n, return the minimum number of operations to get the character 'A'
13+
* exactly n times on the screen.
14+
*/
15+
16+
/**
17+
* @param {number} n
18+
* @return {number}
19+
*/
20+
var minSteps = function(n) {
21+
let result = 0;
22+
23+
for (let factor = 2; n > 1;) {
24+
while (n % factor === 0) {
25+
result += factor;
26+
n /= factor;
27+
}
28+
factor++;
29+
}
30+
31+
return result;
32+
};

0 commit comments

Comments
 (0)