File tree 2 files changed +33
-0
lines changed
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 489
489
647|[ Palindromic Substrings] ( ./0647-palindromic-substrings.js ) |Medium|
490
490
648|[ Replace Words] ( ./0648-replace-words.js ) |Medium|
491
491
649|[ Dota2 Senate] ( ./0649-dota2-senate.js ) |Medium|
492
+ 650|[ 2 Keys Keyboard] ( ./0650-2-keys-keyboard.js ) |Medium|
492
493
653|[ Two Sum IV - Input is a BST] ( ./0653-two-sum-iv-input-is-a-bst.js ) |Easy|
493
494
654|[ Maximum Binary Tree] ( ./0654-maximum-binary-tree.js ) |Medium|
494
495
680|[ Valid Palindrome II] ( ./0680-valid-palindrome-ii.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments