Skip to content

Commit b492292

Browse files
authored
Create 650. 2 Keys Keyboard (#561)
2 parents 92833f5 + 517a971 commit b492292

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

650. 2 Keys Keyboard

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
int minSteps(int n) {
4+
int curr = 1;
5+
int copy = 0;
6+
int steps = 0;
7+
8+
while(curr<n){
9+
if((n-curr)%curr==0){
10+
copy = curr;
11+
steps += 2;
12+
}
13+
else{
14+
steps += 1;
15+
}
16+
curr += copy;
17+
}
18+
19+
return steps;
20+
}
21+
};

0 commit comments

Comments
 (0)