Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita3fefa0

Browse files
authored
Refactored Broken Calculator.java
1 parentf9a8262 commita3fefa0

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
classSolution {
2-
publicintbrokenCalc(intX,intY) {
3-
intcount =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-
returncount +X -Y;
2+
publicintbrokenCalc(intX,intY) {
3+
intcount =0;
4+
while (Y >X) {
5+
count++;
6+
Y =Y %2 ==1 ?Y +1 :Y /2;
177
}
8+
returncount +X -Y;
9+
}
1810
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp