-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path650.2-keys-keyboard.java
More file actions
75 lines (63 loc) · 1.04 KB
/
Copy path650.2-keys-keyboard.java
File metadata and controls
75 lines (63 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
class Solution {
public int minSteps(int n) {
if(n == 1)
return 0;
if((n&(n-1))==0)
return 2*setbit(n);
int ans = Integer.MAX_VALUE;
for(int i=n/2;i>=1;i--){
if(i == 1)
ans = Math.min(n, ans);
else
if(n%i == 0)
ans = Math.min(ans, i+minSteps(n/i));
}
return ans;
}
public int setbit(int n){
int ans = -1;
while(n != 0){
ans++;
n = n/2;
}
return ans;
}
}
/*
if n = 1
A
ans - 0
n=2
ans - 2
n =3
ans -3
n -4
copy
A
cpy -1 A
past -1 AA
copy -1 AA
paste -1 AAAA
n -5
cpy -1 A
past - 1 AA
cp
n-7 - A
cpy 1 A
past 1 AA
copy 1 AA
past 1 AAAA
past 1 AAAAAA
32/2 past
copy
16/2 past
copy
8/2 past
cpy
4/2 past
cpy
2/2 past
1 -copy
34
17
*/