-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path991.java
More file actions
35 lines (35 loc) · 914 Bytes
/
991.java
File metadata and controls
35 lines (35 loc) · 914 Bytes
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
__________________________________________________________________________________________________
sample 0 ms submission
class Solution {
public int brokenCalc(int X, int Y) {
if (X > Y){
return X - Y;
}
if ((X + 1)*2 == Y || (X-1)*2 == Y){
return 2;
}
int count =0;
while (Y > X ){
if (Y % 2 == 1){
Y++;
} else{
Y /=2;
}
count++;
}
return count+X-Y;
}
}
__________________________________________________________________________________________________
sample 31648 kb submission
class Solution {
public int brokenCalc(int X, int Y) {
int res = 0;
while (Y > X) {
Y = Y % 2 > 0 ? Y + 1 : Y / 2;
res++;
}
return res + X - Y;
}
}
__________________________________________________________________________________________________