Skip to content

Commit a3fefa0

Browse files
authored
Refactored Broken Calculator.java
1 parent f9a8262 commit a3fefa0

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

Medium/Broken Calculator.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
class Solution {
2-
public int brokenCalc(int X, int Y) {
3-
int count = 0;
4-
5-
while (Y > X) {
6-
if (Y % 2 == 0) {
7-
Y = Y / 2;
8-
}
9-
else {
10-
Y++;
11-
}
12-
13-
count++;
14-
}
15-
16-
return count + X - Y;
2+
public int brokenCalc(int X, int Y) {
3+
int count = 0;
4+
while (Y > X) {
5+
count++;
6+
Y = Y % 2 == 1 ? Y + 1 : Y / 2;
177
}
8+
return count + X - Y;
9+
}
1810
}

0 commit comments

Comments
 (0)